From 338a8008376abcaefa3d0a1240424d13a9c54707 Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Fri, 10 Sep 2021 17:10:24 +0200 Subject: [PATCH] Merge "templateParameterClick" and "choose" events We don't need to distinguish between these any more. Both are "active", i.e. both focus the widget on the right side of the dialog. Sometimes the "choose" event is fired to actually add or remove a parameter. Sometimes it's fired, but the state of the parameter doesn't change (for whatever reason, i.e. because the parameter name was clicked instead of the checkbox). There is nothing to do in this case, except for the focus change. Change-Id: I3c7c0c81a075ccff76eda0a4fb2aa1ac7be3cec5 --- ...lusionOutlineParameterSelectWidget.test.js | 2 +- ...ransclusionOutlineParameterSelectWidget.js | 16 +++----------- ....ui.MWTransclusionOutlineTemplateWidget.js | 21 ------------------- 3 files changed, 4 insertions(+), 35 deletions(-) diff --git a/modules/ve-mw/tests/ui/widgets/ve.ui.MWTransclusionOutlineParameterSelectWidget.test.js b/modules/ve-mw/tests/ui/widgets/ve.ui.MWTransclusionOutlineParameterSelectWidget.test.js index 94616c6d54..3f9ee2de0f 100644 --- a/modules/ve-mw/tests/ui/widgets/ve.ui.MWTransclusionOutlineParameterSelectWidget.test.js +++ b/modules/ve-mw/tests/ui/widgets/ve.ui.MWTransclusionOutlineParameterSelectWidget.test.js @@ -20,7 +20,7 @@ QUnit.test( 'interaction with items', ( assert ) => { assert.ok( item.isSelected(), 'clicking the checkbox selects the item' ); let eventsFired = 0; - widget.connect( this, { templateParameterClick: () => eventsFired++ } ); + widget.connect( this, { choose: () => eventsFired++ } ); widget.onMouseDown( { which: OO.ui.MouseButtons.LEFT, diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineParameterSelectWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineParameterSelectWidget.js index 4c2ceef57e..20c259223b 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineParameterSelectWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineParameterSelectWidget.js @@ -43,15 +43,6 @@ OO.mixinClass( ve.ui.MWTransclusionOutlineParameterSelectWidget, OO.ui.mixin.Tab * @param {boolean} selected */ -/** - * This is fired instead of the "choose" event from the {@see OO.ui.SelectWidget} base class when - * pressing enter/click on a parameter that's already selected. - * - * @event templateParameterClick - * @param {ve.ui.MWTransclusionOutlineParameterWidget} item - * @param {boolean} selected - */ - /* Static Methods */ /** @@ -136,14 +127,14 @@ ve.ui.MWTransclusionOutlineParameterSelectWidget.prototype.onFocus = function () /** * @inheritDoc OO.ui.SelectWidget * @param {jQuery.Event} e - * @fires templateParameterClick + * @fires choose */ ve.ui.MWTransclusionOutlineParameterSelectWidget.prototype.onMouseDown = function ( e ) { if ( e.which === OO.ui.MouseButtons.LEFT ) { var item = this.findTargetItem( e ); // Same as pressing enter, see below. if ( item && item.isSelected() ) { - this.emit( 'templateParameterClick', item, item.isSelected() ); + this.emit( 'choose', item, item.isSelected() ); // Don't call the parent, i.e. can't click to unselect the item return false; @@ -158,7 +149,6 @@ ve.ui.MWTransclusionOutlineParameterSelectWidget.prototype.onMouseDown = functio * @param {KeyboardEvent} e * @fires choose * @fires templateParameterSelectionChanged - * @fires templateParameterClick */ ve.ui.MWTransclusionOutlineParameterSelectWidget.prototype.onDocumentKeyDown = function ( e ) { var item; @@ -188,7 +178,7 @@ ve.ui.MWTransclusionOutlineParameterSelectWidget.prototype.onDocumentKeyDown = f item = this.findHighlightedItem(); // Same as clicking with the mouse, see above. if ( item && item.isSelected() ) { - this.emit( 'templateParameterClick', item, item.isSelected() ); + this.emit( 'choose', item, item.isSelected() ); e.preventDefault(); // Don't call the parent, i.e. can't use enter to unselect the item diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineTemplateWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineTemplateWidget.js index adea47c2f0..48c9b3fc64 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineTemplateWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineTemplateWidget.js @@ -53,8 +53,6 @@ ve.ui.MWTransclusionOutlineTemplateWidget = function VeUiMWTransclusionOutlineTe .connect( this, { choose: 'onTemplateParameterChoose', templateParameterSelectionChanged: 'onTemplateParameterSelectionChanged', - // Note that choose implies focus, but not the other way around - templateParameterClick: 'onTemplateParameterClick', change: 'onParameterWidgetListChanged' } ); @@ -200,25 +198,6 @@ ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onTemplateParameterSelection } }; -/** - * @private - * @param {OO.ui.OptionWidget} item - * @param {boolean} selected - * @fires focusTemplateParameterById - */ -ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onTemplateParameterClick = function ( item, selected ) { - // Fail-safe. There should be no code-path that calls this with false. - if ( !selected ) { - return; - } - - var paramName = item.getData(), - param = this.templateModel.getParameter( paramName ); - if ( param ) { - this.emit( 'focusTemplateParameterById', param.getId() ); - } -}; - /** * @private * @param {OO.ui.Element[]} items