Only resolve wikitext promise when progress dialog has closed

Logically depends on I0cdb004011 to fix the bug.

Bug: T182402
Change-Id: I8ecd695c052a6c759b8261e81fb25c771bdf3d56
This commit is contained in:
Ed Sanders 2017-12-12 16:22:34 +00:00 committed by Jforrester
parent 58c5643f1e
commit b38500f102

View file

@ -128,7 +128,7 @@ ve.dm.MWWikitextSurfaceFragment.prototype.unwrapText = function ( before, after
* @inheritdoc * @inheritdoc
*/ */
ve.dm.MWWikitextSurfaceFragment.prototype.convertToSource = function ( doc ) { ve.dm.MWWikitextSurfaceFragment.prototype.convertToSource = function ( doc ) {
var wikitextPromise; var wikitextPromise, progressPromise;
if ( !doc.data.hasContent() ) { if ( !doc.data.hasContent() ) {
return $.Deferred().resolve( '' ).promise(); return $.Deferred().resolve( '' ).promise();
@ -137,15 +137,21 @@ ve.dm.MWWikitextSurfaceFragment.prototype.convertToSource = function ( doc ) {
wikitextPromise = ve.init.target.getWikitextFragment( doc, false ); wikitextPromise = ve.init.target.getWikitextFragment( doc, false );
// TODO: Emit an event to trigger the progress bar // 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' ) wikitextPromise, ve.msg( 'visualeditor-generating-wikitext-progress' )
).done( function ( progressBar, cancelPromise ) { ).then( function ( progressBar, cancelPromise ) {
cancelPromise.fail( function () { cancelPromise.fail( function () {
wikitextPromise.abort(); 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();
} );
}; };
/** /**