From c3c3c60f1f32813ffab2f296f52caf1204fde49e Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Sat, 10 Mar 2018 18:30:12 +0000 Subject: [PATCH] Clear VE autosave whenever WikiEditor is loaded Bug: T189381 Change-Id: I21a76dc32327d6c6e72a793d9b579cb7b6a5e32e --- .../targets/ve.init.mw.DesktopArticleTarget.init.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js index 46afecb7fc..a84ea38c18 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js +++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js @@ -1111,10 +1111,11 @@ ); } - // Add the switch button to wikitext ?action=edit or ?action=submit pages + // Add the switch button to WikiEditor on ?action=edit or ?action=submit pages if ( init.isVisualAvailable && - [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 + [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 && + $( '#wpTextbox1' ).length ) { mw.loader.load( 'ext.visualEditor.switching' ); $( '#wpTextbox1' ).on( 'wikiEditor-toolbar-doneInitialSections', function () { @@ -1176,6 +1177,12 @@ // Remember that the user wanted wikitext, at least this time mw.libs.ve.setEditorPreference( 'wikitext' ); + + // If the user has loaded WikiEditor, clear any auto-save state they + // may have from a previous VE session + // We don't have access to the VE session storage methods, but invalidating + // the docstate is sufficient to prevent the data from being used. + mw.storage.session.remove( 've-docstate' ); } init.setupEditLinks();