diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWWikitextLinkAnnotationInspector.js b/modules/ve-mw/ui/inspectors/ve.ui.MWWikitextLinkAnnotationInspector.js index 80f0d85f76..bd6f9f0489 100644 --- a/modules/ve-mw/ui/inspectors/ve.ui.MWWikitextLinkAnnotationInspector.js +++ b/modules/ve-mw/ui/inspectors/ve.ui.MWWikitextLinkAnnotationInspector.js @@ -83,18 +83,25 @@ ve.ui.MWWikitextLinkAnnotationInspector.prototype.getTeardownProcess = function // Call grand-parent return ve.ui.FragmentInspector.prototype.getTeardownProcess.call( this, data ) .first( function () { - var insertion, + var insertion, insert, annotation = this.getAnnotation(), fragment = this.getFragment(), surfaceModel = fragment.getSurface(); 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 ); } - // Action is async, so we use auto select to ensure the content is selected - fragment.setAutoSelect( true ); 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 ) { // Restore selection to what it was before we expanded it surfaceModel.setSelection( this.previousSelection );