diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js index e6292a79e1..8034a8e70b 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js @@ -126,7 +126,7 @@ ve.ui.MWTransclusionDialog.prototype.addTemplatePlaceholder = function () { }; /** - * Handle add content button click events. + * Handle add wikitext button click or hotkey events. * * @private */ @@ -138,10 +138,19 @@ ve.ui.MWTransclusionDialog.prototype.addWikitext = function () { * Handle add parameter hotkey events. * * @private + * @param {jQuery.Event} e Key down event */ -ve.ui.MWTransclusionDialog.prototype.addParameter = function () { - var partId = this.bookletLayout.getTopLevelPartIdForSelection(), +ve.ui.MWTransclusionDialog.prototype.addParameter = function ( e ) { + // Check if the focus was in e.g. a parameter list or filter input when the hotkey was pressed + var partId = this.bookletLayout.sidebar.findPartIdContainingElement( e.target ), part = this.transclusionModel.getPartFromId( partId ); + + if ( !( part instanceof ve.dm.MWTemplateModel ) ) { + // Otherwise add to the template that's currently selected via its title or parameter + partId = this.bookletLayout.getTopLevelPartIdForSelection(); + part = this.transclusionModel.getPartFromId( partId ); + } + if ( !( part instanceof ve.dm.MWTemplateModel ) ) { return; } @@ -248,7 +257,7 @@ ve.ui.MWTransclusionDialog.prototype.onKeyDown = function ( e ) { trigger = this.hotkeyTriggers[ hotkey ]; if ( trigger && ( !trigger.validTypes || trigger.validTypes.test( e.target.nodeName ) ) ) { - trigger.handler(); + trigger.handler( e ); e.preventDefault(); e.stopPropagation(); } diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineWidget.js index b8ebee94a6..9fc5f42237 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineWidget.js @@ -163,6 +163,25 @@ ve.ui.MWTransclusionOutlineWidget.prototype.toggleHasValueByPageName = function templatePartWidget.toggleHasValue( idParts[ 1 ], hasValue ); }; +/** + * Checks if the provided DOM element belongs to the DOM structure of one of the top-level + * {@see ve.ui.MWTransclusionOutlinePartWidget}s, and returns its id. Useful for e.g. mouse click or + * keyboard handlers. + * + * @param {HTMLElement} element + * @return {string|undefined} Always a top-level part id, e.g. "part_0" + */ +ve.ui.MWTransclusionOutlineWidget.prototype.findPartIdContainingElement = function ( element ) { + if ( element ) { + for ( var id in this.partWidgets ) { + var part = this.partWidgets[ id ]; + if ( $.contains( part.$element[ 0 ], element ) ) { + return id; + } + } + } +}; + /** * Removes all {@see ve.ui.MWTransclusionOutlinePartWidget}, i.e. empties the list. */