jquery.textSelection: Remove incorrect browser hack for old Opera
authorBartosz Dziewoński <matma.rex@gmail.com>
Mon, 5 Feb 2018 22:13:50 +0000 (23:13 +0100)
committerJforrester <jforrester@wikimedia.org>
Wed, 7 Feb 2018 18:53:39 +0000 (18:53 +0000)
This code appears to be incorrect, at least on Opera 12.18 on Windows 10,
where I just tested it. It causes the selection to be misaligned, rather
than correct it.

For example, the following code:

    $textbox.textSelection( 'encapsulateSelection', { peri: 'foo\nfoo' } );

Causes the selection to extend one character past the inserted text with
the hack, and to be shown correctly without the hack.

It is theoretically possible that this hack was necessary for some other
operating system, but then it should have also been applied to 'insertText'.
Also, Opera 12 only has a usage share (barely) large enough to show up on
<https://analytics.wikimedia.org/dashboards/browsers/> on Windows (XP).

Change-Id: Ifee877c6202bcfc0fecb65220e34b4b39659dbeb

resources/src/jquery/jquery.textSelection.js

index 7ec9882..27d5fc7 100644 (file)
                                                this.value.slice( endPos );
                                        // Setting this.value scrolls the textarea to the top, restore the scroll position
                                        this.scrollTop = scrollTop;
                                                this.value.slice( endPos );
                                        // Setting this.value scrolls the textarea to the top, restore the scroll position
                                        this.scrollTop = scrollTop;
-                                       if ( window.opera ) {
-                                               pre = pre.replace( /\r?\n/g, '\r\n' );
-                                               selText = selText.replace( /\r?\n/g, '\r\n' );
-                                               post = post.replace( /\r?\n/g, '\r\n' );
-                                       }
                                        if ( isSample && options.selectPeri && ( !options.splitlines || ( options.splitlines && selText.indexOf( '\n' ) === -1 ) ) ) {
                                                this.selectionStart = startPos + pre.length;
                                                this.selectionEnd = startPos + pre.length + selText.length;
                                        if ( isSample && options.selectPeri && ( !options.splitlines || ( options.splitlines && selText.indexOf( '\n' ) === -1 ) ) ) {
                                                this.selectionStart = startPos + pre.length;
                                                this.selectionEnd = startPos + pre.length + selText.length;