Vlad Kurkin (b_vladi) wrote in changelog,
Vlad Kurkin
b_vladi
changelog

[livejournal] r19281: LJSUP-8986: Autocomplete incorrect worki...

Committer: vkurkin
LJSUP-8986: Autocomplete incorrect working at IE8
U   trunk/htdocs/js/basic.js
Modified: trunk/htdocs/js/basic.js
===================================================================
--- trunk/htdocs/js/basic.js	2011-06-14 04:09:37 UTC (rev 19280)
+++ trunk/htdocs/js/basic.js	2011-06-14 07:45:01 UTC (rev 19281)
@@ -686,35 +686,33 @@
 			start = node.selectionStart;
 			end = node.selectionEnd;
 		} else if(node.createTextRange){
-			var range = document.selection.createRange(),
-				dup = range.duplicate();
+			var range = document.selection.createRange();
+			if(range.parentElement() == node){
+				var dup = range.duplicate();
 
-			if(node.type == 'text'){
-				start = -dup.moveStart('character', -100000);
-				end = start + range.text.length;
-			} else // textarea
-			{
-				var rex = /\r/g;
-				dup.moveToElementText(node);
-				dup.setEndPoint('EndToStart', range);
-				start = dup.text.replace(rex, '').length;
-				dup.setEndPoint('EndToEnd', range);
-				end = dup.text.replace(rex, '').length;
-				dup = document.selection.createRange();
-				dup.moveToElementText(node);
-				dup.moveStart('character', start);
-				while(dup.move('character', -dup.compareEndPoints('StartToStart', range))){
-					start++;
+				if(node.type == 'text'){
+					node.focus();
+					start = -dup.moveStart('character', -node.value.length);
+					end = start + range.text.length;
+				} else {// textarea
+					var rex = /\r/g;
+					dup.moveToElementText(node);
+					dup.setEndPoint('EndToStart', range);
+					start = dup.text.replace(rex, '').length;
+					dup.setEndPoint('EndToEnd', range);
+					end = dup.text.replace(rex, '').length;
+					dup = document.selection.createRange();
+					dup.moveToElementText(node);
+					dup.moveStart('character', start);
+					while(dup.move('character', -dup.compareEndPoints('StartToStart', range))){
+						start++;
+					}
+					dup.moveStart('character', end - start);
+					while(dup.move('character', -dup.compareEndPoints('StartToEnd', range))){
+						end++;
+					}
 				}
-				dup.moveStart('character', end - start);
-				while(dup.move('character', -dup.compareEndPoints('StartToEnd', range))){
-					end++;
-				}
-			}
 
-			// range.parentElement() drops selection in IE 7-8 in some cases.
-			if(range.parentElement() != node){
-				start = end = undefined;
 			}
 		}
 
@@ -729,7 +727,6 @@
 		node.focus();
 		if(node.setSelectionRange){
 			node.setSelectionRange(start, end);
-			return;
 		}
 		// IE, "else" for opera 10
 		else if(document.selection && document.selection.createRange){

Tags: b_vladi, js, livejournal
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments