jenkins-bot has submitted this change and it was merged.

Change subject: MWLinkAnnotationInspector: change where auto switch to external 
occurs
......................................................................


MWLinkAnnotationInspector: change where auto switch to external occurs

OnInternalLinkChange happened post-validation, and received an already title-
normalized version of the href. Thus `file://` would become `:File://`. As
such, hook up to the raw internal link input change event, and judge what the
user actually entered.

Bug: T138956
Change-Id: I0f9f3de3b7bf6e5430e55fa69626522b0c74296a
---
M modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js
1 file changed, 28 insertions(+), 21 deletions(-)

Approvals:
  Esanders: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js 
b/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js
index 3acee5e..973f500 100644
--- a/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js
+++ b/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js
@@ -76,6 +76,7 @@
        this.externalAnnotationInput.connect( this, { change: 
'onExternalLinkChange' } );
        this.internalAnnotationInput.input.getResults().connect( this, { 
choose: 'onFormSubmit' } );
        // Form submit only auto triggers on enter when there is one input
+       this.internalAnnotationInput.getTextInputWidget().connect( this, { 
change: 'onInternalLinkInputChange' } );
        this.internalAnnotationInput.getTextInputWidget().connect( this, { 
enter: 'onFormSubmit' } );
        this.externalAnnotationInput.getTextInputWidget().connect( this, { 
enter: 'onFormSubmit' } );
 
@@ -110,27 +111,7 @@
  *
  * @param {ve.dm.MWInternalLinkAnnotation} annotation Annotation
  */
-ve.ui.MWLinkAnnotationInspector.prototype.onInternalLinkChange = function ( 
annotation ) {
-       var href = annotation ? annotation.getAttribute( 'title' ) : '';
-
-       // If this looks like an external link, switch to the correct card.
-       // Note: We don't care here if it's a *valid* link, so we just
-       // check whether it looks like a URI -- i.e. whether it starts with
-       // something that appears to be a schema per RFC1630. Later the external
-       // link inspector will use getExternalLinkUrlProtocolsRegExp for 
validity
-       // checking.
-       // Note 2: RFC1630 might be too broad in practice. You don't really see
-       // schemas that use the full set of allowed characters, and we might get
-       // more false positives by checking for them.
-       // Note 3: We allow protocol-relative URIs here.
-       if (
-               !this.allowProtocolInInternal &&
-               /^(?:[a-z][a-z0-9\$\-_@\.&!\*"'\(\),]*:)?\/\//i.test( href )
-       ) {
-               this.linkTypeIndex.setCard( 'external' );
-               // Changing card focuses and selects the input, so collapse the 
cursor back to the end.
-               
this.externalAnnotationInput.getTextInputWidget().moveCursorToEnd();
-       }
+ve.ui.MWLinkAnnotationInspector.prototype.onInternalLinkChange = function () {
        this.updateActions();
 };
 
@@ -186,6 +167,32 @@
 };
 
 /**
+ * Handle change events on the internal link widget's input
+ *
+ * @param {string} value Current value of input widget
+ */
+ve.ui.MWLinkAnnotationInspector.prototype.onInternalLinkInputChange = function 
( value ) {
+       // If this looks like an external link, switch to the correct card.
+       // Note: We don't care here if it's a *valid* link, so we just
+       // check whether it looks like a URI -- i.e. whether it starts with
+       // something that appears to be a schema per RFC1630. Later the external
+       // link inspector will use getExternalLinkUrlProtocolsRegExp for 
validity
+       // checking.
+       // Note 2: RFC1630 might be too broad in practice. You don't really see
+       // schemas that use the full set of allowed characters, and we might get
+       // more false positives by checking for them.
+       // Note 3: We allow protocol-relative URIs here.
+       if (
+               !this.allowProtocolInInternal &&
+               /^(?:[a-z][a-z0-9\$\-_@\.&!\*"'\(\),]*:)?\/\//i.test( 
value.trim() )
+       ) {
+               this.linkTypeIndex.setCard( 'external' );
+               // Changing card focuses and selects the input, so collapse the 
cursor back to the end.
+               
this.externalAnnotationInput.getTextInputWidget().moveCursorToEnd();
+       }
+};
+
+/**
  * @inheritdoc
  */
 ve.ui.MWLinkAnnotationInspector.prototype.createAnnotationInput = function () {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I0f9f3de3b7bf6e5430e55fa69626522b0c74296a
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: DLynch <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to