From 34344e50b69e16e7029e8cd25e6822a3f3828bda Mon Sep 17 00:00:00 2001 From: Esanders Date: Mon, 10 Dec 2018 17:58:59 +0000 Subject: [PATCH] Revert "textSelection: Use execcommand to replace text" This reverts commit 4ba80ca7f5472dbdbccc1afa9ebf3549700f2778. Change-Id: Iffeb021a1a6b204ea5ca6d8e16bab4d703ee7f6c --- resources/src/jquery/jquery.textSelection.js | 27 ++++++++------------ 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/resources/src/jquery/jquery.textSelection.js b/resources/src/jquery/jquery.textSelection.js index cbbed995a6..6b4ab979a1 100644 --- a/resources/src/jquery/jquery.textSelection.js +++ b/resources/src/jquery/jquery.textSelection.js @@ -71,10 +71,7 @@ setContents: function ( content ) { return this.each( function () { var scrollTop = this.scrollTop; - this.select(); - if ( !document.execCommand( 'insertText', false, content ) ) { - $( this ).val( content ); - } + $( this ).val( content ); // Setting this.value may scroll the textarea, restore the scroll position this.scrollTop = scrollTop; } ); @@ -111,19 +108,17 @@ return this.each( function () { var allText, currSelection, startPos, endPos; - if ( !document.execCommand( 'insertText', false, value ) ) { - allText = $( this ).textSelection( 'getContents' ); - currSelection = $( this ).textSelection( 'getCaretPosition', { startAndEnd: true } ); - startPos = currSelection[ 0 ]; - endPos = currSelection[ 1 ]; + allText = $( this ).textSelection( 'getContents' ); + currSelection = $( this ).textSelection( 'getCaretPosition', { startAndEnd: true } ); + startPos = currSelection[ 0 ]; + endPos = currSelection[ 1 ]; - $( this ).textSelection( 'setContents', allText.slice( 0, startPos ) + value + - allText.slice( endPos ) ); - $( this ).textSelection( 'setSelection', { - start: startPos, - end: startPos + value.length - } ); - } + $( this ).textSelection( 'setContents', allText.slice( 0, startPos ) + value + + allText.slice( endPos ) ); + $( this ).textSelection( 'setSelection', { + start: startPos, + end: startPos + value.length + } ); } ); }, -- 2.20.1