From: Esanders Date: Mon, 10 Dec 2018 17:58:59 +0000 (+0000) Subject: Revert "textSelection: Use execcommand to replace text" X-Git-Tag: 1.34.0-rc.0~3290^2 X-Git-Url: http://git.cyclocoop.org//%27%40script%40/%27?a=commitdiff_plain;h=34344e50b69e16e7029e8cd25e6822a3f3828bda;p=lhc%2Fweb%2Fwiklou.git Revert "textSelection: Use execcommand to replace text" This reverts commit 4ba80ca7f5472dbdbccc1afa9ebf3549700f2778. Change-Id: Iffeb021a1a6b204ea5ca6d8e16bab4d703ee7f6c --- 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 + } ); } ); },