Merge "Prefer adding parameter to currently focussed template"

This commit is contained in:
jenkins-bot 2022-07-28 11:34:38 +00:00 committed by Gerrit Code Review
commit 13c2a24f6c
2 changed files with 32 additions and 4 deletions

View file

@ -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();
}

View file

@ -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.
*/