Revert "textSelection: Use execcommand to replace text"
authorEsanders <esanders@wikimedia.org>
Mon, 10 Dec 2018 17:58:59 +0000 (17:58 +0000)
committerEsanders <esanders@wikimedia.org>
Mon, 10 Dec 2018 17:58:59 +0000 (17:58 +0000)
This reverts commit 4ba80ca7f5472dbdbccc1afa9ebf3549700f2778.

Change-Id: Iffeb021a1a6b204ea5ca6d8e16bab4d703ee7f6c

resources/src/jquery/jquery.textSelection.js

index cbbed99..6b4ab97 100644 (file)
                        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;
                                } );
                                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
+                                       } );
                                } );
                        },