CopyTextLayout: Only select-all on focus
authorEd Sanders <esanders@wikimedia.org>
Mon, 29 Jul 2019 14:51:33 +0000 (15:51 +0100)
committerEd Sanders <esanders@wikimedia.org>
Mon, 29 Jul 2019 14:53:56 +0000 (15:53 +0100)
This allows users to partially select the text, which is useful
in some cases, but still makes it easy to copy either using a keyboard
shortcut or the ButtonWidget.

Bug: T110579
Change-Id: I5be1530bb2cca9f8251e2e1c87a85e1e79cfe47f

resources/src/mediawiki.widgets/mw.widgets.CopyTextLayout.js

index 65e7eb7..56419ae 100644 (file)
@@ -54,7 +54,7 @@
 
                // Events
                this.button.connect( this, { click: 'onButtonClick' } );
-               this.textInput.$input.on( 'click', this.onInputClick.bind( this ) );
+               this.textInput.$input.on( 'focus', this.onInputFocus.bind( this ) );
 
                this.$element.addClass( 'mw-widget-copyTextLayout' );
        };
        };
 
        /**
-        * Handle button click events
+        * Handle text widget focus events
         */
-       mw.widgets.CopyTextLayout.prototype.onInputClick = function () {
-               this.selectText();
+       mw.widgets.CopyTextLayout.prototype.onInputFocus = function () {
+               if ( !this.selecting ) {
+                       this.selectText();
+               }
        };
 
        /**
                        scrollTop = input.scrollTop,
                        scrollLeft = input.scrollLeft;
 
+               this.selecting = true;
                this.textInput.select();
+               this.selecting = false;
 
                // Restore scroll position
                input.scrollTop = scrollTop;