Esanders has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/397861 )
Change subject: Allow access to a fragment's async state ...................................................................... Allow access to a fragment's async state Change-Id: I0cdb004011bc932e90d67db76bbc810255edc3a3 --- M src/ce/ve.ce.Surface.js M src/dm/ve.dm.SourceSurfaceFragment.js M src/dm/ve.dm.SurfaceFragment.js M src/ui/ve.ui.Surface.js 4 files changed, 44 insertions(+), 22 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/61/397861/1 diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js index ae35351..356a7d3 100644 --- a/src/ce/ve.ce.Surface.js +++ b/src/ce/ve.ce.Surface.js @@ -2347,22 +2347,24 @@ } } - if ( this.getSelection().isNativeCursor() ) { - // Restore focus and scroll position - this.$documentNode[ 0 ].focus(); - this.$window.scrollTop( beforePasteData.scrollTop ); - // setTimeout: Firefox sometimes doesn't change scrollTop immediately when pasting - // line breaks at the end of a line so do it again later. - setTimeout( function () { + targetFragment.getPending().then( function () { + if ( view.getSelection().isNativeCursor() ) { + // Restore focus and scroll position + view.$documentNode[ 0 ].focus(); view.$window.scrollTop( beforePasteData.scrollTop ); - } ); - } + // setTimeout: Firefox sometimes doesn't change scrollTop immediately when pasting + // line breaks at the end of a line so do it again later. + setTimeout( function () { + view.$window.scrollTop( beforePasteData.scrollTop ); + } ); + } - // If orignal selection was linear, switch to end of pasted text - if ( fragment.getSelection() instanceof ve.dm.LinearSelection ) { - targetFragment.collapseToEnd().select(); - this.checkSequences( /* isPaste */ true ); - } + // If orignal selection was linear, switch to end of pasted text + if ( fragment.getSelection() instanceof ve.dm.LinearSelection ) { + targetFragment.collapseToEnd().select(); + view.checkSequences( /* isPaste */ true ); + } + } ); }; /** diff --git a/src/dm/ve.dm.SourceSurfaceFragment.js b/src/dm/ve.dm.SourceSurfaceFragment.js index bcb9ddf..ca67bf9 100644 --- a/src/dm/ve.dm.SourceSurfaceFragment.js +++ b/src/dm/ve.dm.SourceSurfaceFragment.js @@ -111,6 +111,7 @@ fragment = this; if ( !range ) { + this.pushPending( $.Deferred().resolve().promise() ); return this; } @@ -146,18 +147,19 @@ return ve.dm.SourceSurfaceFragment.super.prototype.insertContent.call( this, data ); } - this.convertToSource( doc ) - .done( function ( source ) { + this.pushPending( this.convertToSource( doc ).then( + function ( source ) { if ( source ) { // Parent method ve.dm.SourceSurfaceFragment.super.prototype.insertContent.call( fragment, source.trim() ); } else { fragment.removeContent(); } - } ) - .fail( function () { + }, + function () { ve.error( 'Failed to convert document', arguments ); - } ); + } ) + ); return this; }; diff --git a/src/dm/ve.dm.SurfaceFragment.js b/src/dm/ve.dm.SurfaceFragment.js index 7d2c97b..79de5a7 100644 --- a/src/dm/ve.dm.SurfaceFragment.js +++ b/src/dm/ve.dm.SurfaceFragment.js @@ -31,6 +31,7 @@ this.surface = surface; this.selection = selection || surface.getSelection(); this.leafNodes = null; + this.pending = []; // Initialization this.historyPointer = this.document.getCompleteHistoryLength(); @@ -645,6 +646,24 @@ }; /** + * Push a promise to the fragment's pending list + * + * @param {jQuery.Promise} promise Promise + */ +ve.dm.SurfaceFragment.prototype.pushPending = function ( promise ) { + this.pending.push( promise ); +}; + +/** + * Get a promise that resolves when the pending list is complete + * + * @return {jQuery.Promise} Promise + */ +ve.dm.SurfaceFragment.prototype.getPending = function () { + return $.when.apply( $, this.pending ); +}; + +/** * Apply the fragment's range to the surface as a selection. * * @method diff --git a/src/ui/ve.ui.Surface.js b/src/ui/ve.ui.Surface.js index 257e442..8e041a4 100644 --- a/src/ui/ve.ui.Surface.js +++ b/src/ui/ve.ui.Surface.js @@ -744,10 +744,9 @@ }; ve.ui.Surface.prototype.showProgress = function () { - var dialogs = this.dialogs, - progresses = this.progresses; + var progresses = this.progresses; - dialogs.openWindow( 'progress', { progresses: progresses, $returnFocusTo: null } ); + this.dialogs.openWindow( 'progress', { progresses: progresses, $returnFocusTo: null } ); this.progresses = []; }; -- To view, visit https://gerrit.wikimedia.org/r/397861 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0cdb004011bc932e90d67db76bbc810255edc3a3 Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits