mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
autosave: Handle switched document with no transactions
Always store immediately if fromEditedState is true. Also now that we only store if there is state to recover, remove the check for transactions before deciding to show the notification. Change-Id: I5357a9098b91e303f5c71881ea03a080d2969fff
This commit is contained in:
parent
007bb6fa09
commit
4c759e2587
|
@ -463,11 +463,10 @@ ve.init.mw.ArticleTarget.prototype.surfaceReady = function () {
|
||||||
if ( this.recovered ) {
|
if ( this.recovered ) {
|
||||||
// Restore auto-saved transactions if document state was recovered
|
// Restore auto-saved transactions if document state was recovered
|
||||||
try {
|
try {
|
||||||
if ( surfaceModel.restoreChanges() ) {
|
surfaceModel.restoreChanges();
|
||||||
mw.notify( ve.msg( 'visualeditor-autosave-recovered-text' ), {
|
mw.notify( ve.msg( 'visualeditor-autosave-recovered-text' ), {
|
||||||
title: ve.msg( 'visualeditor-autosave-recovered-title' )
|
title: ve.msg( 'visualeditor-autosave-recovered-title' )
|
||||||
} );
|
} );
|
||||||
}
|
|
||||||
} catch ( e ) {
|
} catch ( e ) {
|
||||||
mw.log.warn( e );
|
mw.log.warn( e );
|
||||||
mw.notify( ve.msg( 'visualeditor-autosave-not-recovered-text' ), {
|
mw.notify( ve.msg( 'visualeditor-autosave-not-recovered-text' ), {
|
||||||
|
@ -477,10 +476,19 @@ ve.init.mw.ArticleTarget.prototype.surfaceReady = function () {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// ...otherwise store this document state for later recovery
|
// ...otherwise store this document state for later recovery
|
||||||
// Wait for the first change before doing this.
|
if ( !this.fromEditedState ) {
|
||||||
surfaceModel.once( 'undoStackChange', function () {
|
// Store immediately if the document was previously edited
|
||||||
target.storeDocState( target.originalHtml );
|
// (e.g. in a different mode)
|
||||||
} );
|
this.storeDocState( this.originalHtml );
|
||||||
|
} else {
|
||||||
|
// Only store after the first change if this is an unmodified document
|
||||||
|
surfaceModel.once( 'undoStackChange', function () {
|
||||||
|
// Check the surface hasn't been destroyed
|
||||||
|
if ( target.getSurface() ) {
|
||||||
|
target.storeDocState( target.originalHtml );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Start auto-saving transactions
|
// Start auto-saving transactions
|
||||||
surfaceModel.startStoringChanges();
|
surfaceModel.startStoringChanges();
|
||||||
|
|
Loading…
Reference in a new issue