diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js index 5830930328..157b523d91 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js @@ -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 ); diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineButtonWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineButtonWidget.js index d1e433172f..6d69ccf25e 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineButtonWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineButtonWidget.js @@ -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 ); diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlinePartWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlinePartWidget.js index bab8811e3a..c0704a6152 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlinePartWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlinePartWidget.js @@ -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() ); } };