From b38500f10215861f5252556c0de0fc4cdaa14640 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Tue, 12 Dec 2017 16:22:34 +0000 Subject: [PATCH] Only resolve wikitext promise when progress dialog has closed Logically depends on I0cdb004011 to fix the bug. Bug: T182402 Change-Id: I8ecd695c052a6c759b8261e81fb25c771bdf3d56 --- .../ve-mw/dm/ve.dm.MWWikitextSurfaceFragment.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/ve-mw/dm/ve.dm.MWWikitextSurfaceFragment.js b/modules/ve-mw/dm/ve.dm.MWWikitextSurfaceFragment.js index 338003bce9..0d672b67e4 100644 --- a/modules/ve-mw/dm/ve.dm.MWWikitextSurfaceFragment.js +++ b/modules/ve-mw/dm/ve.dm.MWWikitextSurfaceFragment.js @@ -128,7 +128,7 @@ ve.dm.MWWikitextSurfaceFragment.prototype.unwrapText = function ( before, after * @inheritdoc */ ve.dm.MWWikitextSurfaceFragment.prototype.convertToSource = function ( doc ) { - var wikitextPromise; + var wikitextPromise, progressPromise; if ( !doc.data.hasContent() ) { return $.Deferred().resolve( '' ).promise(); @@ -137,15 +137,21 @@ ve.dm.MWWikitextSurfaceFragment.prototype.convertToSource = function ( doc ) { wikitextPromise = ve.init.target.getWikitextFragment( doc, false ); // TODO: Emit an event to trigger the progress bar - ve.init.target.getSurface().createProgress( + progressPromise = ve.init.target.getSurface().createProgress( wikitextPromise, ve.msg( 'visualeditor-generating-wikitext-progress' ) - ).done( function ( progressBar, cancelPromise ) { + ).then( function ( progressBar, cancelPromise ) { cancelPromise.fail( function () { wikitextPromise.abort(); } ); } ); - return wikitextPromise; + return $.when( wikitextPromise, progressPromise ).then( function ( wikitext ) { + var deferred = $.Deferred(); + setTimeout( function () { + deferred.resolve( wikitext ); + }, ve.init.target.getSurface().dialogs.getTeardownDelay() ); + return deferred.promise(); + } ); }; /**