mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-13 17:48:17 +00:00
Change confirmation behaviour when abandoning template edits
Previously, it was possible to close a dialog with active edits by pressing the "<" button or pressing escape. A change was made to confirm the user's intent before abandoning their changes, see Ia8935b5b1acb This patch fixes a bug where the user's intent is always confirmed while editing a template, even if the user has made no changes. This was because for technical reasons we trimmed whitespace before making a comparison with the new template case, but that caused the comparison with the edit case to always fail because existing templates are padded with whitespace. This could have been solved by moving the trim operation into the new template flow. This patch would still have been necessary to prevent a bug if the default value had trimmable whitespace. I have opted to keep the whitespace behaviour for edits for consistency. Bug: T334513 Change-Id: I7b3370c86df67c36fc63a1f1d0e7004a098a1950
This commit is contained in:
parent
b3b30bb4a5
commit
3c6f0a918c
|
@ -197,13 +197,13 @@ ve.ui.MWExtensionWindow.prototype.isModified = ve.ui.MWExtensionWindow.prototype
|
|||
* @return {boolean} mwData would contain new user input
|
||||
*/
|
||||
ve.ui.MWExtensionWindow.prototype.hasMeaningfulEdits = function () {
|
||||
var mwDataBaseline;
|
||||
let mwDataBaseline;
|
||||
if ( this.originalMwData ) {
|
||||
mwDataBaseline = this.originalMwData;
|
||||
} else {
|
||||
mwDataBaseline = this.getNewElement().attributes.mw;
|
||||
}
|
||||
var mwDataCopy = ve.copy( mwDataBaseline );
|
||||
const mwDataCopy = ve.copy( mwDataBaseline );
|
||||
this.updateMwData( mwDataCopy );
|
||||
|
||||
// We have some difficulty here. `updateMwData()` in this class calls on
|
||||
|
@ -213,11 +213,19 @@ ve.ui.MWExtensionWindow.prototype.hasMeaningfulEdits = function () {
|
|||
// We don't want to touch `this.input` or `prototype.updateMwData` because
|
||||
// they're overridden in subclasses. Therefore, we consider whitespace-only
|
||||
// changes to a new element to be non-meaningful too.
|
||||
var changed = OO.getProp( mwDataCopy, 'body', 'extsrc' );
|
||||
const changed = OO.getProp( mwDataCopy, 'body', 'extsrc' );
|
||||
if ( changed !== undefined ) {
|
||||
OO.setProp( mwDataCopy, 'body', 'extsrc', changed.trim() );
|
||||
}
|
||||
|
||||
// Also trim the baseline. In "edit" mode we likely have added whitespace,
|
||||
// and in "insert" mode we don't want to break if the default value starts
|
||||
// or ends with whitespace.
|
||||
const baselineChanged = OO.getProp( mwDataBaseline, 'body', 'extsrc' );
|
||||
if ( baselineChanged !== undefined ) {
|
||||
OO.setProp( mwDataBaseline, 'body', 'extsrc', baselineChanged.trim() );
|
||||
}
|
||||
|
||||
return !ve.compare( mwDataBaseline, mwDataCopy );
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue