mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
Prefer adding parameter to currently focussed template
Instead of the template that's currently selected. That's confusing, e.g. when you click one of the search fields, search for a parameter, can't fine it, and press ctrl+shift+d to add an undocumented parameter. Or you navigate the list of parameters with the cursor keys, can't find the parameter you are looking for, and press ctrl+shift+d to add it. Still falls back to the selection when the focus is outside of the sidebar. We suggest to merge this before UX review, and review it later in demo time. It's easy to undo if necessary. Bug: T313388 Change-Id: I9848dd0af4fe821526dafc18bbd7cb1ab0e68cfc
This commit is contained in:
parent
d70e425fc9
commit
b085d6cf24
|
@ -133,7 +133,7 @@ ve.ui.MWTransclusionDialog.prototype.addTemplatePlaceholder = function () {
|
|||
};
|
||||
|
||||
/**
|
||||
* Handle add content button click events.
|
||||
* Handle add wikitext button click or hotkey events.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
|
@ -145,10 +145,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;
|
||||
}
|
||||
|
@ -255,7 +264,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