Move newline-stripping filter into MWEditSummaryWidget

Edit summaries should always strip newlines, wherever
this widget is used.

Change-Id: I37177771fef831037067d6244fb27cba5e06528b
This commit is contained in:
Ed Sanders 2021-01-13 21:07:30 +00:00
parent 5a370aafb1
commit 443eaded40
2 changed files with 30 additions and 20 deletions

View file

@ -606,17 +606,10 @@ 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();
// Show a warning if the user presses Enter
this.editSummaryInput.on( 'enter', function () {
dialog.showMessage(
'keyboard-shortcut-submit',
$( '<p>' ).msg(
@ -625,7 +618,6 @@ ve.ui.MWSaveDialog.prototype.initialize = function () {
),
{ wrap: false }
);
}
} );
// Limit length, and display the remaining characters
this.editSummaryInput.$input.codePointLimit( this.editSummaryCodePointLimit );

View file

@ -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
*