Catrope has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/204077

Change subject: Don't use a inputFilter on LinkTargetInputWidget
......................................................................

Don't use a inputFilter on LinkTargetInputWidget

Fixes I4df99d2c1.

Input filters run on every change making it impossible to
type space at the end of a word, even if you intend to type
something else after it.

Apply the trim only to the annotation, and make sure we don't
reset the input value from the annotation if setValue is triggered
by a change event.

Bug: T94498
Change-Id: Ie01e0f4970757f2983eb3488be805f755f688291
(cherry picked from commit f696ef7da6874398a99bed138264800b70ea0aae)
---
M src/ui/widgets/ve.ui.LinkTargetInputWidget.js
1 file changed, 16 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/77/204077/1

diff --git a/src/ui/widgets/ve.ui.LinkTargetInputWidget.js 
b/src/ui/widgets/ve.ui.LinkTargetInputWidget.js
index e26a5e5..9d270c9 100644
--- a/src/ui/widgets/ve.ui.LinkTargetInputWidget.js
+++ b/src/ui/widgets/ve.ui.LinkTargetInputWidget.js
@@ -16,10 +16,7 @@
 ve.ui.LinkTargetInputWidget = function VeUiLinkTargetInputWidget( config ) {
        // Parent constructor
        OO.ui.TextInputWidget.call( this, $.extend( {
-               validate: 
/^(https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi,
-               inputFilter: function ( target ) {
-                       return target.trim();
-               }
+               validate: /^(https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi
        }, config ) );
 
        // Properties
@@ -64,7 +61,7 @@
                                // If URL is external, flip to LTR. Otherwise, 
set back to RTL
                                widget.setRTL( !isExt );
                        }
-                       widget.setValue( widget.$input.val() );
+                       widget.setValue( widget.$input.val(), true );
                } );
        }
 };
@@ -76,8 +73,9 @@
  *
  * @method
  * @param {string} value New value
+ * @param {boolean} [fromInput] Value was generated from input element
  */
-ve.ui.LinkTargetInputWidget.prototype.setValue = function ( value ) {
+ve.ui.LinkTargetInputWidget.prototype.setValue = function ( value, fromInput ) 
{
        // Keep annotation in sync with value
        value = this.cleanUpValue( value );
        if ( value === '' ) {
@@ -86,9 +84,9 @@
                this.setAnnotation( new ve.dm.LinkAnnotation( {
                        type: 'link',
                        attributes: {
-                               href: value
+                               href: value.trim()
                        }
-               } ) );
+               } ), fromInput );
        }
 
        // Parent method
@@ -102,15 +100,20 @@
  *
  * @method
  * @param {ve.dm.LinkAnnotation} annotation Link annotation
+ * @param {boolean} [fromInput] Annotation was generated from input element 
value
  * @chainable
  */
-ve.ui.LinkTargetInputWidget.prototype.setAnnotation = function ( annotation ) {
+ve.ui.LinkTargetInputWidget.prototype.setAnnotation = function ( annotation, 
fromInput ) {
        this.annotation = annotation;
 
-       // Parent method
-       OO.ui.TextInputWidget.prototype.setValue.call(
-               this, this.getTargetFromAnnotation( annotation )
-       );
+       // If this method was triggered by the user typing into the input, 
don't update
+       // the input element to avoid the cursor jumping as the user types
+       if ( !fromInput ) {
+               // Parent method
+               OO.ui.TextInputWidget.prototype.setValue.call(
+                       this, this.getTargetFromAnnotation( annotation )
+               );
+       }
 
        return this;
 };

-- 
To view, visit https://gerrit.wikimedia.org/r/204077
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie01e0f4970757f2983eb3488be805f755f688291
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: wmf/1.25wmf24
Gerrit-Owner: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Esanders <esand...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to