From f814ea719b8bc0508bb289af8df8873feaa56d4b Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Fri, 25 Sep 2015 21:29:10 +0100 Subject: [PATCH] MWLinkAnnotationInspector: Use TitleSearchWidget instead of TitleInputWidget Depends on I335bd912d in MediaWiki core. Bug: T101169 Change-Id: I2932c9df5444d1363af5af9b438bb905ed298148 --- extension.json | 2 +- .../ve.ui.MWLinkAnnotationInspector.js | 39 +++++++++---------- .../ve.ui.MWLinkAnnotationInspector.css | 22 ++++++++++- .../ve.ui.MWInternalLinkAnnotationWidget.js | 12 ++++-- 4 files changed, 50 insertions(+), 25 deletions(-) diff --git a/extension.json b/extension.json index 876da80b08..ce48594014 100644 --- a/extension.json +++ b/extension.json @@ -22,7 +22,7 @@ "license-name": "MIT", "type": "other", "requires": { - "MediaWiki": ">= 1.26.0" + "MediaWiki": ">= 1.27.0" }, "callback": "VisualEditorHooks::onRegistration", "config": { diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js b/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js index c60102539a..525d0963ae 100644 --- a/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js +++ b/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js @@ -46,14 +46,9 @@ ve.ui.MWLinkAnnotationInspector.static.actions = ve.ui.MWLinkAnnotationInspector * @inheritdoc */ ve.ui.MWLinkAnnotationInspector.prototype.initialize = function () { - var overlay = this.manager.getOverlay(); - // Properties this.allowProtocolInInternal = false; - this.internalAnnotationInput = new ve.ui.MWInternalLinkAnnotationWidget( { - // Sub-classes may want to know where to position overlays - $overlay: overlay ? overlay.$element : this.$frame - } ); + this.internalAnnotationInput = new ve.ui.MWInternalLinkAnnotationWidget(); this.externalAnnotationInput = new ve.ui.MWExternalLinkAnnotationWidget(); this.linkTypeSelect = new OO.ui.TabSelectWidget( { @@ -77,6 +72,12 @@ ve.ui.MWLinkAnnotationInspector.prototype.initialize = function () { this.internalAnnotationInput.connect( this, { change: 'onInternalLinkChange' } ); this.externalAnnotationInput.connect( this, { change: 'onExternalLinkChange' } ); + this.internalAnnotationInput.input.results.connect( this, { + add: 'onInternalLinkChangeResultsChange' + // Listening to remove causes a flicker, and is not required + // as 'add' is always trigger on a change too + } ); + // Parent method ve.ui.MWLinkAnnotationInspector.super.prototype.initialize.call( this ); @@ -128,6 +129,16 @@ ve.ui.MWLinkAnnotationInspector.prototype.onInternalLinkChange = function ( anno this.updateActions(); }; +/** + * Handle list change events ('add') from the interal link's result widget + * + * @param {OO.ui.OptionWidget[]} items Added items + * @param {number} index Index of insertion point + */ +ve.ui.MWLinkAnnotationInspector.prototype.onInternalLinkChangeResultsChange = function () { + this.updateSize(); +}; + /** * Handle change events on the external link widget * @@ -189,16 +200,6 @@ ve.ui.MWLinkAnnotationInspector.prototype.getSetupProcess = function ( data ) { }, this ); }; -/** - * @inheritdoc - */ -ve.ui.MWLinkAnnotationInspector.prototype.getReadyProcess = function ( data ) { - return ve.ui.MWLinkAnnotationInspector.super.prototype.getReadyProcess.call( this, data ) - .next( function () { - this.internalAnnotationInput.getTextInputWidget().populateLookupMenu(); - }, this ); -}; - /** * @inheritdoc */ @@ -263,6 +264,8 @@ ve.ui.MWLinkAnnotationInspector.prototype.onLinkTypeSelectSelect = function () { this.annotationInput = this.createAnnotationInput(); this.form.$element.append( this.annotationInput.$element ); + this.updateSize(); + // If the user manually switches to internal links with an external link in the input, remember this if ( !isExternal && inputHasProtocol ) { this.allowProtocolInInternal = true; @@ -272,10 +275,6 @@ ve.ui.MWLinkAnnotationInspector.prototype.onLinkTypeSelectSelect = function () { // Firefox moves the cursor to the beginning this.annotationInput.getTextInputWidget().$input[ 0 ].setSelectionRange( end, end ); - if ( !isExternal ) { - this.annotationInput.getTextInputWidget().populateLookupMenu(); - } - this.updateActions(); }; diff --git a/modules/ve-mw/ui/styles/inspectors/ve.ui.MWLinkAnnotationInspector.css b/modules/ve-mw/ui/styles/inspectors/ve.ui.MWLinkAnnotationInspector.css index 85c2b18d2d..05d1bb2325 100644 --- a/modules/ve-mw/ui/styles/inspectors/ve.ui.MWLinkAnnotationInspector.css +++ b/modules/ve-mw/ui/styles/inspectors/ve.ui.MWLinkAnnotationInspector.css @@ -7,4 +7,24 @@ .ve-ui-mwLinkAnnotationInspector-linkTypeSelect { margin: -0.75em -0.75em 0.75em -0.75em; -} \ No newline at end of file +} + +.ve-ui-linkAnnotationWidget .mw-widget-titleSearchWidget { + position: relative; +} + +.ve-ui-linkAnnotationWidget .mw-widget-titleSearchWidget .oo-ui-searchWidget-query { + padding: 0; + height: auto; + border: 0; +} + +.ve-ui-linkAnnotationWidget .mw-widget-titleSearchWidget .oo-ui-searchWidget-query .oo-ui-textInputWidget { + margin: 0; +} + +.ve-ui-linkAnnotationWidget .mw-widget-titleSearchWidget .oo-ui-searchWidget-results { + position: relative; + top: 0; + padding: 3em 0 0 0; +} diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkAnnotationWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkAnnotationWidget.js index 9a86617746..dfa556704d 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkAnnotationWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkAnnotationWidget.js @@ -53,13 +53,19 @@ ve.ui.MWInternalLinkAnnotationWidget.static.getTextFromAnnotation = function ( a * @return {OO.ui.TextInputWidget} Text input widget */ ve.ui.MWInternalLinkAnnotationWidget.prototype.createInputWidget = function ( config ) { - return new mw.widgets.TitleInputWidget( { - $overlay: config.$overlay, + return new mw.widgets.TitleSearchWidget( ve.extendObject( { icon: 'search', showImages: mw.config.get( 'wgVisualEditor' ).usePageImages, showDescriptions: mw.config.get( 'wgVisualEditor' ).usePageDescriptions, cache: ve.init.platform.linkCache - } ); + }, config ) ); +}; + +/** + * @inheritdoc + */ +ve.ui.MWInternalLinkAnnotationWidget.prototype.getTextInputWidget = function () { + return this.input.query; }; /**