From 1597eeda1eb638dc95b3b191bf9b0e5b1c5ec4be Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Mon, 29 Jul 2019 15:51:33 +0100 Subject: [PATCH] CopyTextLayout: Only select-all on focus 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 --- .../mediawiki.widgets/mw.widgets.CopyTextLayout.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/resources/src/mediawiki.widgets/mw.widgets.CopyTextLayout.js b/resources/src/mediawiki.widgets/mw.widgets.CopyTextLayout.js index 65e7eb782a..56419aee68 100644 --- a/resources/src/mediawiki.widgets/mw.widgets.CopyTextLayout.js +++ b/resources/src/mediawiki.widgets/mw.widgets.CopyTextLayout.js @@ -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' ); }; @@ -90,10 +90,12 @@ }; /** - * 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(); + } }; /** @@ -104,7 +106,9 @@ scrollTop = input.scrollTop, scrollLeft = input.scrollLeft; + this.selecting = true; this.textInput.select(); + this.selecting = false; // Restore scroll position input.scrollTop = scrollTop; -- 2.20.1