} 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 ) {
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();
'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':
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" );