mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
Wire move/delete hotkeys to button functionallity
The behavior is now consistant with what would happen when the buttons are triggered. Instead of emitting a button click I directly wired the methods that will by triggerd by the click. This might make it easier to remove the old sidbar later. To avoid movement when the buttons should be disabled, an additional check was added to the onMove method. It's not identical to the more complex check in the outlineControlsWidget, but should be enough for our use case. The onDelete method already just does nothing if nothing is selected. Bug: T300971 Change-Id: I8a278c9657c91fd648944b5a8c1204c9fff75b7e
This commit is contained in:
parent
99878d3634
commit
ef87088198
|
@ -94,9 +94,13 @@ ve.ui.MWTransclusionDialog.prototype.onOutlineControlsMove = function ( places )
|
|||
return;
|
||||
}
|
||||
|
||||
var index = this.transclusionModel.getParts().indexOf( part );
|
||||
var newPlace = this.transclusionModel.getParts().indexOf( part ) + places;
|
||||
if ( newPlace < 0 || newPlace >= this.transclusionModel.getParts().length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Move part to new location, and if dialog is loaded switch to new part page
|
||||
var promise = this.transclusionModel.addPart( part, index + places );
|
||||
var promise = this.transclusionModel.addPart( part, newPlace );
|
||||
if ( this.loaded && !this.preventReselection ) {
|
||||
promise.done( this.focusPart.bind( this, part.getId() ) );
|
||||
}
|
||||
|
@ -220,7 +224,7 @@ ve.ui.MWTransclusionDialog.prototype.setupHotkeyTriggers = function () {
|
|||
addParameter: meta + 'shift+d',
|
||||
moveUp: meta + 'shift+up',
|
||||
moveDown: meta + 'shift+down',
|
||||
remove: meta + 'del'
|
||||
remove: meta + 'delete'
|
||||
};
|
||||
|
||||
this.hotkeyTriggers = {};
|
||||
|
@ -228,6 +232,10 @@ ve.ui.MWTransclusionDialog.prototype.setupHotkeyTriggers = function () {
|
|||
this.hotkeyTriggers[ hotkeys.addWikitext ] = this.addContent.bind( this );
|
||||
this.hotkeyTriggers[ hotkeys.addParameter ] = this.addParameter.bind( this );
|
||||
|
||||
this.hotkeyTriggers[ hotkeys.moveUp ] = this.onOutlineControlsMove.bind( this, -1 );
|
||||
this.hotkeyTriggers[ hotkeys.moveDown ] = this.onOutlineControlsMove.bind( this, 1 );
|
||||
this.hotkeyTriggers[ hotkeys.remove ] = this.onOutlineControlsRemove.bind( this );
|
||||
|
||||
this.addHotkeyToTitle( this.addTemplateButton, hotkeys.addTemplate );
|
||||
this.addHotkeyToTitle( this.addContentButton, hotkeys.addWikitext );
|
||||
this.addHotkeyToTitle( this.addParameterButton, hotkeys.addParameter );
|
||||
|
|
|
@ -78,22 +78,6 @@ ve.ui.MWTransclusionOutlineButtonWidget.prototype.onKeyDown = function ( e ) {
|
|||
// The default behavior of pressing space is to scroll down
|
||||
e.preventDefault();
|
||||
return;
|
||||
} else if ( ( e.which === OO.ui.Keys.UP || e.which === OO.ui.Keys.DOWN ) &&
|
||||
withMetaKey && e.shiftKey &&
|
||||
!e.altKey
|
||||
) {
|
||||
this.emit( 'keyPressed', e.which );
|
||||
// TODO: Do we need e.preventDefault() and/or e.stopPropagation() here?
|
||||
return;
|
||||
} else if ( ( e.which === OO.ui.Keys.DELETE || ( isMac && e.which === OO.ui.Keys.BACKSPACE ) ) &&
|
||||
withMetaKey &&
|
||||
!e.shiftKey && !e.altKey
|
||||
) {
|
||||
this.emit( 'keyPressed', OO.ui.Keys.DELETE );
|
||||
// To not trigger the "clear cache" feature in Chrome we must do both
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
return;
|
||||
}
|
||||
|
||||
return OO.ui.mixin.ButtonElement.prototype.onKeyDown.call( this, e );
|
||||
|
|
|
@ -93,28 +93,12 @@ OO.inheritClass( ve.ui.MWTransclusionOutlinePartWidget, OO.ui.Widget );
|
|||
|
||||
/**
|
||||
* @private
|
||||
* @param {number} key Note that some keys only make it here when Ctrl or Ctrl+Shift is pressed
|
||||
* @param {number} key
|
||||
* @fires transclusionPartSoftSelected
|
||||
*/
|
||||
ve.ui.MWTransclusionOutlinePartWidget.prototype.onHeaderKeyPressed = function ( key ) {
|
||||
switch ( key ) {
|
||||
case OO.ui.Keys.SPACE:
|
||||
this.emit( 'transclusionPartSoftSelected', this.getData() );
|
||||
break;
|
||||
case OO.ui.Keys.UP:
|
||||
case OO.ui.Keys.DOWN:
|
||||
// Modelled after {@see ve.ui.MWTransclusionDialog.onOutlineControlsMove}
|
||||
var transclusion = this.part.getTransclusion(),
|
||||
parts = transclusion.getParts(),
|
||||
offset = key === OO.ui.Keys.UP ? -1 : 1,
|
||||
newIndex = parts.indexOf( this.part ) + offset;
|
||||
if ( newIndex >= 0 && newIndex < parts.length ) {
|
||||
transclusion.addPart( this.part, newIndex );
|
||||
}
|
||||
break;
|
||||
case OO.ui.Keys.DELETE:
|
||||
this.part.remove();
|
||||
break;
|
||||
if ( key === OO.ui.Keys.SPACE ) {
|
||||
this.emit( 'transclusionPartSoftSelected', this.getData() );
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue