Merge "NWE: Fix selection when applying async links"

This commit is contained in:
jenkins-bot 2018-04-19 16:01:22 +00:00 committed by Gerrit Code Review
commit 9ecd73f771

View file

@ -83,18 +83,25 @@ ve.ui.MWWikitextLinkAnnotationInspector.prototype.getTeardownProcess = function
// Call grand-parent // Call grand-parent
return ve.ui.FragmentInspector.prototype.getTeardownProcess.call( this, data ) return ve.ui.FragmentInspector.prototype.getTeardownProcess.call( this, data )
.first( function () { .first( function () {
var insertion, var insertion, insert,
annotation = this.getAnnotation(), annotation = this.getAnnotation(),
fragment = this.getFragment(), fragment = this.getFragment(),
surfaceModel = fragment.getSurface(); surfaceModel = fragment.getSurface();
if ( data && data.action === 'done' && annotation ) { if ( data && data.action === 'done' && annotation ) {
if ( this.initialSelection.isCollapsed() && ( insertion = this.getInsertionData() ).length ) { insert = this.initialSelection.isCollapsed() && ( insertion = this.getInsertionData() ).length;
if ( insert ) {
fragment.insertContent( insertion ); fragment.insertContent( insertion );
} }
// Action is async, so we use auto select to ensure the content is selected
fragment.setAutoSelect( true );
fragment.annotateContent( 'set', annotation ); fragment.annotateContent( 'set', annotation );
// Fix selection after annotating is complete
fragment.getPending().then( function () {
if ( insert ) {
fragment.collapseToEnd().select();
} else {
fragment.select();
}
} );
} else if ( !data.action ) { } else if ( !data.action ) {
// Restore selection to what it was before we expanded it // Restore selection to what it was before we expanded it
surfaceModel.setSelection( this.previousSelection ); surfaceModel.setSelection( this.previousSelection );