jenkins-bot has submitted this change and it was merged.
Change subject: Select the correct annotation in MWLinkTargetInputWidget
......................................................................
Select the correct annotation in MWLinkTargetInputWidget
The solution to this problem was two-fold:
* Initialize the menu selection based on current annotation data
* Don't re-open the LinkTargetInput suggestions menu after choosing
It unfortunately involves assuming that setAnnotation will always synchronously
emit 'change' events.
Bug: 65343
Change-Id: Ia92751add5ee59ba581141a31c8433c5e7e521a5
---
M modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
1 file changed, 25 insertions(+), 2 deletions(-)
Approvals:
Catrope: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
b/modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
index e145c64..96fc170 100644
--- a/modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
+++ b/modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
@@ -27,6 +27,7 @@
// Properties
this.annotation = null;
+ this.choosing = false;
// Events
this.lookupMenu.connect( this, { 'choose': 'onLookupMenuItemChoose' } );
@@ -58,10 +59,25 @@
*/
ve.ui.MWLinkTargetInputWidget.prototype.onLookupMenuItemChoose = function (
item ) {
if ( item ) {
+ // WARNING: This assumes that #setAnnotation will emit `change`
events synchronously
+ // TODO: Consider how this trick can be solved better, and
possibly pushed upstream to
+ // OO.ui.LookupInputWidget so others don't fall into this trap
+ this.choosing = true;
this.setAnnotation( item.getData() );
+ this.choosing = false;
} else if ( this.annotation ) {
this.annotation = null;
this.emit( 'change', this.getValue() );
+ }
+};
+
+/**
+ * @inheritdoc
+ */
+ve.ui.MWLinkTargetInputWidget.prototype.onLookupInputChange = function () {
+ // WARNING: See #onLookupMenuItemChoose for why this is fragile
+ if ( !this.choosing ) {
+ this.openLookupMenu();
}
};
@@ -237,8 +253,15 @@
ve.ui.MWLinkTargetInputWidget.prototype.initializeLookupMenuSelection =
function () {
var item;
- // Parent method
- OO.ui.LookupInputWidget.prototype.initializeLookupMenuSelection.call(
this );
+ if ( this.annotation ) {
+ this.lookupMenu.selectItem( this.lookupMenu.getItemFromData(
this.annotation ) );
+ }
+
+ item = this.lookupMenu.getSelectedItem();
+ if ( !item ) {
+ // Parent method
+
OO.ui.LookupInputWidget.prototype.initializeLookupMenuSelection.call( this );
+ }
// Update annotation to match selected item
item = this.lookupMenu.getSelectedItem();
--
To view, visit https://gerrit.wikimedia.org/r/155673
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia92751add5ee59ba581141a31c8433c5e7e521a5
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Trevor Parscal <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits