diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js index 90b455784b..989ef8b74e 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js @@ -606,26 +606,18 @@ ve.ui.MWSaveDialog.prototype.initialize = function () { this.editSummaryInput = new ve.ui.MWEditSummaryWidget( { $overlay: this.$overlay, placeholder: ve.msg( 'visualeditor-editsummary' ), - classes: [ 've-ui-mwSaveDialog-summary' ], - inputFilter: function ( value ) { - // Prevent the user from inputting newlines (this kicks in on paste, etc.) - return value.replace( /\r?\n/g, ' ' ); - } + classes: [ 've-ui-mwSaveDialog-summary' ] } ); - // Prevent the user from inputting newlines from keyboard - this.editSummaryInput.$input.on( 'keypress', function ( e ) { - if ( e.which === OO.ui.Keys.ENTER ) { - e.preventDefault(); - - dialog.showMessage( - 'keyboard-shortcut-submit', - $( '

' ).msg( - 'visualeditor-savedialog-keyboard-shortcut-submit', - new ve.ui.Trigger( ve.ui.commandHelpRegistry.lookup( 'dialogConfirm' ).shortcuts[ 0 ] ).getMessage() - ), - { wrap: false } - ); - } + // Show a warning if the user presses Enter + this.editSummaryInput.on( 'enter', function () { + dialog.showMessage( + 'keyboard-shortcut-submit', + $( '

' ).msg( + 'visualeditor-savedialog-keyboard-shortcut-submit', + new ve.ui.Trigger( ve.ui.commandHelpRegistry.lookup( 'dialogConfirm' ).shortcuts[ 0 ] ).getMessage() + ), + { wrap: false } + ); } ); // Limit length, and display the remaining characters this.editSummaryInput.$input.codePointLimit( this.editSummaryCodePointLimit ); diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWEditSummaryWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWEditSummaryWidget.js index d8437a3dd9..ae80db1636 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWEditSummaryWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWEditSummaryWidget.js @@ -20,7 +20,12 @@ ve.ui.MWEditSummaryWidget = function VeUiMWEditSummaryWidget( config ) { config = config || {}; // Parent method - ve.ui.MWEditSummaryWidget.super.apply( this, arguments ); + ve.ui.MWEditSummaryWidget.super.call( this, ve.extendObject( { + inputFilter: function ( value ) { + // Prevent the user from inputting newlines (this kicks in on paste, etc.) + return value.replace( /\r?\n/g, ' ' ); + } + }, config ) ); // Mixin method OO.ui.mixin.LookupElement.call( this, ve.extendObject( { @@ -97,6 +102,19 @@ ve.ui.MWEditSummaryWidget.static.getMatchingSummaries = function ( summaries, qu /* Methods */ +/** + * @inheritdoc + */ +ve.ui.MWEditSummaryWidget.prototype.onKeyPress = function ( e ) { + if ( e.which === OO.ui.Keys.ENTER ) { + e.preventDefault(); + } + // Grand-parent method + // Multi-line only fires 'enter' on ctrl+enter, but this should + // fire on plain enter as it behaves like a single line input. + OO.ui.TextInputWidget.prototype.onKeyPress.call( this, e ); +}; + /** * Get recent edit summaries for the logged in user *