r62590 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62589‎ | r62590 | r62591 >
Date:19:51, 16 February 2010
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: (bug 22479) Cursor moves to start of edit box after inserting special characters. Was caused by the selSC/selEC finding algorithm using < instead of <=. The same algorithm was completely broken for multiline inserts because it was written for in-order traversal and stuck in reverse-order traversal code, fixed this as well.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -72,7 +72,7 @@
7373 array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ),
7474 array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 7 ),
7575 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 27 ),
76 - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 135 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 136 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 31 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 49 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 15 ),
@@ -82,10 +82,10 @@
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 2 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 257 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 258 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 257 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 258 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -747,27 +747,27 @@
748748 range.insertNode( firstNode );
749749 lastNode = lastNode || firstNode;
750750 var newOffset = offset + insertLines[i].length;
751 - if ( !selSC && pre.length < newOffset ) {
 751+ if ( !selEC && post.length <= newOffset ) {
 752+ selEC = firstNode;
 753+ selEO = selEC.nodeValue.length - ( post.length - offset );
 754+ }
 755+ if ( selEC && !selSC && pre.length >= insertText.length - newOffset ) {
752756 selSC = firstNode;
753 - selSO = pre.length - offset;
 757+ selSO = pre.length - ( insertText.length - newOffset );
754758 }
755 - if ( selSC && insertText.length - post.length < newOffset ) {
756 - selEC = firstNode;
757 - selEO = insertText.length - pre.length - offset;
758 - }
759759 offset = newOffset;
760760 if ( i > 0 ) {
761761 firstNode = context.$iframe[0].contentWindow.document.createElement( 'br' );
762762 range.insertNode( firstNode );
763763 newOffset = offset + 1;
764 - if ( !selSC && pre.length < newOffset ) {
 764+ if ( !selEC && post.length <= newOffset ) {
 765+ selEC = firstNode;
 766+ selEO = 1 - ( post.length - offset );
 767+ }
 768+ if ( selEC && !selSC && pre.length >= insertText.length - newOffset ) {
765769 selSC = firstNode;
766 - selSO = pre.length - offset;
 770+ selSO = pre.length - ( insertText.length - newOffset );
767771 }
768 - if ( selSC && insertText.length - post.length < newOffset ) {
769 - selEC = firstNode;
770 - selEO = insertText.length - pre.length - offset;
771 - }
772772 offset = newOffset;
773773 }
774774 }
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -7180,27 +7180,27 @@
71817181 range.insertNode( firstNode );
71827182 lastNode = lastNode || firstNode;
71837183 var newOffset = offset + insertLines[i].length;
7184 - if ( !selSC && pre.length < newOffset ) {
 7184+ if ( !selEC && post.length <= newOffset ) {
 7185+ selEC = firstNode;
 7186+ selEO = selEC.nodeValue.length - ( post.length - offset );
 7187+ }
 7188+ if ( selEC && !selSC && pre.length >= insertText.length - newOffset ) {
71857189 selSC = firstNode;
7186 - selSO = pre.length - offset;
 7190+ selSO = pre.length - ( insertText.length - newOffset );
71877191 }
7188 - if ( selSC && insertText.length - post.length < newOffset ) {
7189 - selEC = firstNode;
7190 - selEO = insertText.length - pre.length - offset;
7191 - }
71927192 offset = newOffset;
71937193 if ( i > 0 ) {
71947194 firstNode = context.$iframe[0].contentWindow.document.createElement( 'br' );
71957195 range.insertNode( firstNode );
71967196 newOffset = offset + 1;
7197 - if ( !selSC && pre.length < newOffset ) {
 7197+ if ( !selEC && post.length <= newOffset ) {
 7198+ selEC = firstNode;
 7199+ selEO = 1 - ( post.length - offset );
 7200+ }
 7201+ if ( selEC && !selSC && pre.length >= insertText.length - newOffset ) {
71987202 selSC = firstNode;
7199 - selSO = pre.length - offset;
 7203+ selSO = pre.length - ( insertText.length - newOffset );
72007204 }
7201 - if ( selSC && insertText.length - post.length < newOffset ) {
7202 - selEC = firstNode;
7203 - selEO = insertText.length - pre.length - offset;
7204 - }
72057205 offset = newOffset;
72067206 }
72077207 }
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -485,10 +485,10 @@
486486 if(!atStart){pre="\n"+options.pre;}
487487 if(!atEnd){post+="\n";}}
488488 var insertText="";if(options.splitlines){for(var j=0;j<selTextArr.length;j++){insertText=insertText+pre+selTextArr[j]+post;if(j!=selTextArr.length-1){insertText+="\n";}}}else{insertText=pre+selText+post;}
489 -var insertLines=insertText.split("\n");range.extractContents();var firstNode=null,lastNode=null;var selSC=null,selEC=null,selSO=null,selEO=null,offset=0;for(var i=insertLines.length-1;i>=0;i--){firstNode=context.$iframe[0].contentWindow.document.createTextNode(insertLines[i]);range.insertNode(firstNode);lastNode=lastNode||firstNode;var newOffset=offset+insertLines[i].length;if(!selSC&&pre.length<newOffset){selSC=firstNode;selSO=pre.length-offset;}
490 -if(selSC&&insertText.length-post.length<newOffset){selEC=firstNode;selEO=insertText.length-pre.length-offset;}
491 -offset=newOffset;if(i>0){firstNode=context.$iframe[0].contentWindow.document.createElement('br');range.insertNode(firstNode);newOffset=offset+1;if(!selSC&&pre.length<newOffset){selSC=firstNode;selSO=pre.length-offset;}
492 -if(selSC&&insertText.length-post.length<newOffset){selEC=firstNode;selEO=insertText.length-pre.length-offset;}
 489+var insertLines=insertText.split("\n");range.extractContents();var firstNode=null,lastNode=null;var selSC=null,selEC=null,selSO=null,selEO=null,offset=0;for(var i=insertLines.length-1;i>=0;i--){firstNode=context.$iframe[0].contentWindow.document.createTextNode(insertLines[i]);range.insertNode(firstNode);lastNode=lastNode||firstNode;var newOffset=offset+insertLines[i].length;if(!selEC&&post.length<=newOffset){selEC=firstNode;selEO=selEC.nodeValue.length-(post.length-offset);}
 490+if(selEC&&!selSC&&pre.length>=insertText.length-newOffset){selSC=firstNode;selSO=pre.length-(insertText.length-newOffset);}
 491+offset=newOffset;if(i>0){firstNode=context.$iframe[0].contentWindow.document.createElement('br');range.insertNode(firstNode);newOffset=offset+1;if(!selEC&&post.length<=newOffset){selEC=firstNode;selEO=1-(post.length-offset);}
 492+if(selEC&&!selSC&&pre.length>=insertText.length-newOffset){selSC=firstNode;selSO=pre.length-(insertText.length-newOffset);}
493493 offset=newOffset;}}
494494 if(firstNode){context.fn.scrollToTop($(firstNode.parentNode));}
495495 if(selectAfter){setSelectionTo={startContainer:selSC,endContainer:selEC,start:selSO,end:selEO};}else if(lastNode){setSelectionTo={startContainer:lastNode,endContainer:lastNode,start:lastNode.nodeValue.length,end:lastNode.nodeValue.length};}}else if(context.$iframe[0].contentWindow.document.selection){context.$iframe[0].contentWindow.focus();var range=context.$iframe[0].contentWindow.document.selection.createRange();if(options.ownline&&range.moveStart){var range2=context.$iframe[0].contentWindow.document.selection.createRange();range2.collapse();range2.moveStart('character',-1);if(range2.text!="\r"&&range2.text!="\n"&&range2.text!=""){pre="\n"+pre;}

Status & tagging log