r93372 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93371‎ | r93372 | r93373 >
Date:06:40, 28 July 2011
Author:catrope
Status:ok (Comments)
Tags:
Comment:
Followup r93366: fix Opera bugs in textSelection. All tests pass in Opera now. Before, there were five failures
* replace \r\n with \n in the obtained output from getSelection. This fixes one failure
* In continuation of r93366, which updated post for added newlines in insertText, do the same for pre and also do this in the non-IE branch. This fixes one failure
* Look for \r as well as \n where line endings are concerned in the non-IE branch, just like in the IE branch. This fixes one failure
* Have the test case generator remap selection positions for Opera to account for the fact that a newline is double-counted. This fixes the remaining two failures
Modified paths:
  • /trunk/phase3/resources/jquery/jquery.textSelection.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.js (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.js
@@ -50,14 +50,23 @@
5151 //$textarea.textSelection( 'setContents', opt.before.text); // this method is actually missing atm...
5252 $textarea.val( opt.before.text ); // won't work with the WikiEditor iframe?
5353
 54+ var start = opt.before.start,
 55+ end = opt.before.end;
 56+ if ( window.opera ) {
 57+ // Compensate for Opera's craziness converting "\n" to "\r\n" and counting that as two chars
 58+ var newLinesBefore = opt.before.text.substring( 0, start ).split( "\n" ).length - 1,
 59+ newLinesInside = opt.before.text.substring( start, end ).split( "\n" ).length - 1;
 60+ start += newLinesBefore;
 61+ end += newLinesBefore + newLinesInside;
 62+ }
5463 $textarea.textSelection( 'setSelection', {
55 - start: opt.before.start,
56 - end: opt.before.end
 64+ start: start,
 65+ end: end
5766 });
5867
5968 $textarea.textSelection( 'encapsulateSelection', opt.replace );
6069
61 - var text = $textarea.textSelection( 'getContents' );
 70+ var text = $textarea.textSelection( 'getContents' ).replace( /\r\n/g, "\n" );
6271
6372 equal( text, opt.after.text, 'Checking full text after encapsulation' );
6473
Index: trunk/phase3/resources/jquery/jquery.textSelection.js
@@ -112,11 +112,13 @@
113113 insertText = doSplitLines( selText, pre, post );
114114 }
115115 if ( options.ownline ) {
116 - if ( startPos != 0 && this.value.charAt( startPos - 1 ) != "\n" ) {
 116+ if ( startPos != 0 && this.value.charAt( startPos - 1 ) != "\n" && this.value.charAt( startPos - 1 ) != "\r" ) {
117117 insertText = "\n" + insertText;
 118+ pre += "\n";
118119 }
119 - if ( this.value.charAt( endPos ) != "\n" ) {
 120+ if ( this.value.charAt( endPos ) != "\n" && this.value.charAt( endPos ) != "\r" ) {
120121 insertText += "\n";
 122+ post += "\n";
121123 }
122124 }
123125 this.value = this.value.substring( 0, startPos ) + insertText +
@@ -157,6 +159,7 @@
158160 // FIXME: Which check is correct?
159161 if ( range2.text != "\r" && range2.text != "\n" && range2.text != "" ) {
160162 insertText = "\n" + insertText;
 163+ pre += "\n";
161164 }
162165 var range3 = document.selection.createRange();
163166 range3.collapse( false );
@@ -292,7 +295,7 @@
293296 var length = this.value.length;
294297 // IE doesn't count \n when computing the offset, so we won't either
295298 var newLines = this.value.match( /\n/g );
296 - if ( newLines) length = length - newLines.length;
 299+ if ( newLines ) length = length - newLines.length;
297300 selection.moveStart( 'character', options.start );
298301 selection.moveEnd( 'character', -length + options.end );
299302

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r89403(bug 29105) Splitlines completely messes up selection of inserted text. This ...catrope10:08, 3 June 2011
r93366Fix broken textSelection test case in IE. All textSelection tests are passing...catrope05:57, 28 July 2011

Comments

#Comment by Krinkle (talk | contribs)   06:45, 28 July 2011

Fixes all versions of Opera, leaving no broken tests left ( http://toolserver.org/~krinkle/testswarm/job/258/ ).

Nice! Marking OK.

Status & tagging log