r96579 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96578‎ | r96579 | r96580 >
Date:16:05, 8 September 2011
Author:catrope
Status:ok
Tags:
Comment:
(bug 30130) Add selectionStart and selectionEnd parameters to encapsulateSelection in jquery.textSelection. Modified patch by Santosh (removed whitespace and debugging code, added tests).
Modified paths:
  • /trunk/phase3/resources/jquery/jquery.textSelection.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/jquery/jquery.textSelection.js
@@ -101,11 +101,23 @@
102102 } else if ( this.selectionStart || this.selectionStart == '0' ) {
103103 // Mozilla/Opera
104104 $(this).focus();
 105+ if ( options.selectionStart !== undefined ) {
 106+ $(this).textSelection( 'setSelection', { 'start': options.selectionStart, 'end': options.selectionEnd } );
 107+ }
 108+
105109 var selText = $(this).textSelection( 'getSelection' );
106110 var startPos = this.selectionStart;
107111 var endPos = this.selectionEnd;
108112 var scrollTop = this.scrollTop;
109113 checkSelectedText();
 114+ if ( options.selectionStart !== undefined
 115+ && endPos - startPos != options.selectionEnd - options.selectionStart )
 116+ {
 117+ // This means there is a difference in the selection range returned by browser and what we passed.
 118+ // This happens for Chrome in the case of composite characters. Ref bug #30130
 119+ // Set the startPos to the correct position.
 120+ startPos = options.selectionStart;
 121+ }
110122
111123 var insertText = pre + selText + post;
112124 if ( options.splitlines ) {
@@ -143,6 +155,10 @@
144156 if ( context ) {
145157 context.fn.restoreCursorAndScrollTop();
146158 }
 159+ if ( options.selectionStart !== undefined ) {
 160+ $(this).textSelection( 'setSelection', { 'start': options.selectionStart, 'end': options.selectionEnd } );
 161+ }
 162+
147163 var selText = $(this).textSelection( 'getSelection' );
148164 var scrollTop = this.scrollTop;
149165 var range = document.selection.createRange();
@@ -417,7 +433,9 @@
418434 'ownline': false, // Put the inserted text on a line of its own
419435 'replace': false, // If there is a selection, replace it with peri instead of leaving it alone
420436 'selectPeri': true, // Select the peri text if it was inserted (but not if there was a selection and replace==false, or if splitlines==true)
421 - 'splitlines': false // If multiple lines are selected, encapsulate each line individually
 437+ 'splitlines': false, // If multiple lines are selected, encapsulate each line individually
 438+ 'selectionStart': undefined, // Position to start selection at
 439+ 'selectionEnd': undefined // Position to end selection at. Defaults to start
422440 }, options );
423441 break;
424442 case 'getCaretPosition':
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js
@@ -59,12 +59,11 @@
6060 start += newLinesBefore;
6161 end += newLinesBefore + newLinesInside;
6262 }
63 - $textarea.textSelection( 'setSelection', {
64 - start: start,
65 - end: end
66 - });
6763
68 - $textarea.textSelection( 'encapsulateSelection', opt.replace );
 64+ var options = $.extend( {}, opt.replace ); // Clone opt.replace
 65+ options.selectionStart = start;
 66+ options.selectionEnd = end;
 67+ $textarea.textSelection( 'encapsulateSelection', options );
6968
7069 var text = $textarea.textSelection( 'getContents' ).replace( /\r\n/g, "\n" );
7170

Follow-up revisions

RevisionCommit summaryAuthorDate
r97466Remove webkit specific slow code with generic approach with the help of jquer...santhosh11:07, 19 September 2011
r976021.17wmf1: MFT r96579catrope08:36, 20 September 2011
r976041.18wmf1: MFT r96579, needed for Narayam not to breakcatrope08:41, 20 September 2011
r100495Merge r97604 (r96579 was being a bitch!)reedy02:53, 22 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96415Applying workaround locally within the extension Narayam for webkit browsers ...junaidpv11:39, 7 September 2011

Status & tagging log