http://www.mediawiki.org/wiki/Special:Code/MediaWiki/96579
Revision: 96579
Author: catrope
Date: 2011-09-08 16:05:50 +0000 (Thu, 08 Sep 2011)
Log Message:
-----------
(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
trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js
Modified: trunk/phase3/resources/jquery/jquery.textSelection.js
===================================================================
--- trunk/phase3/resources/jquery/jquery.textSelection.js 2011-09-08
15:52:00 UTC (rev 96578)
+++ trunk/phase3/resources/jquery/jquery.textSelection.js 2011-09-08
16:05:50 UTC (rev 96579)
@@ -101,11 +101,23 @@
} else if ( this.selectionStart || this.selectionStart == '0' )
{
// Mozilla/Opera
$(this).focus();
+ if ( options.selectionStart !== undefined ) {
+ $(this).textSelection( 'setSelection', {
'start': options.selectionStart, 'end': options.selectionEnd } );
+ }
+
var selText = $(this).textSelection( 'getSelection' );
var startPos = this.selectionStart;
var endPos = this.selectionEnd;
var scrollTop = this.scrollTop;
checkSelectedText();
+ if ( options.selectionStart !== undefined
+ && endPos - startPos !=
options.selectionEnd - options.selectionStart )
+ {
+ // This means there is a difference in the
selection range returned by browser and what we passed.
+ // This happens for Chrome in the case of
composite characters. Ref bug #30130
+ // Set the startPos to the correct position.
+ startPos = options.selectionStart;
+ }
var insertText = pre + selText + post;
if ( options.splitlines ) {
@@ -143,6 +155,10 @@
if ( context ) {
context.fn.restoreCursorAndScrollTop();
}
+ if ( options.selectionStart !== undefined ) {
+ $(this).textSelection( 'setSelection', {
'start': options.selectionStart, 'end': options.selectionEnd } );
+ }
+
var selText = $(this).textSelection( 'getSelection' );
var scrollTop = this.scrollTop;
var range = document.selection.createRange();
@@ -417,7 +433,9 @@
'ownline': false, // Put the inserted text on a
line of its own
'replace': false, // If there is a selection,
replace it with peri instead of leaving it alone
'selectPeri': true, // Select the peri text if
it was inserted (but not if there was a selection and replace==false, or if
splitlines==true)
- 'splitlines': false // If multiple lines are
selected, encapsulate each line individually
+ 'splitlines': false, // If multiple lines are
selected, encapsulate each line individually
+ 'selectionStart': undefined, // Position to
start selection at
+ 'selectionEnd': undefined // Position to end
selection at. Defaults to start
}, options );
break;
case 'getCaretPosition':
Modified:
trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js
===================================================================
---
trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js
2011-09-08 15:52:00 UTC (rev 96578)
+++
trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js
2011-09-08 16:05:50 UTC (rev 96579)
@@ -59,12 +59,11 @@
start += newLinesBefore;
end += newLinesBefore + newLinesInside;
}
- $textarea.textSelection( 'setSelection', {
- start: start,
- end: end
- });
- $textarea.textSelection( 'encapsulateSelection', opt.replace );
+ var options = $.extend( {}, opt.replace ); // Clone opt.replace
+ options.selectionStart = start;
+ options.selectionEnd = end;
+ $textarea.textSelection( 'encapsulateSelection', options );
var text = $textarea.textSelection( 'getContents' ).replace(
/\r\n/g, "\n" );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs