mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
Merge "Prefer adding parameter to currently focussed template"
This commit is contained in:
commit
13c2a24f6c
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue