Use new CE Surface selectAnnotation method

Change-Id: Ic26c46d3cdabc7b9949527d04eada5203cf6f7d3
Depends-On: I23f3586e340899801c99b3015e51dd0965a8ef0b
This commit is contained in:
Ed Sanders 2019-04-13 17:04:43 +01:00 committed by Bartosz Dziewoński
parent 7197fd49c3
commit d14d443aff
2 changed files with 6 additions and 21 deletions

View file

@ -75,12 +75,9 @@ ve.ui.MWNumberedExternalLinkNodeContextItem.prototype.onLabelButtonClick = funct
ve.dm.TransactionBuilder.static.newFromReplacement( doc, nodeRange, content )
);
setTimeout( function () {
// Note: we can't rely on surfaceView.activeAnnotations, because the selection-focus created
// by the transaction might be outside the link node. As such, get the node immediately
// after the offset where we inserted the annotation, and then get the closest link
// annotation to it.
var node = surfaceView.getDocument().getNodeAndOffset( nodeRange.start + 1 ).node;
surfaceView.selectNodeContents( $( node ).closest( '.ve-ce-linkAnnotation' )[ 0 ] );
surfaceView.selectAnnotation( function ( view ) {
return view.model instanceof ve.dm.MWExternalLinkAnnotation;
} );
} );
};

View file

@ -135,21 +135,9 @@ ve.ui.MWLinkNodeInspector.prototype.getTeardownProcess = function ( data ) {
ve.dm.TransactionBuilder.static.newFromReplacement( doc, nodeRange, content )
);
setTimeout( function () {
// This just removed the node and turned it into an annotation. Thus, this inspector
// is about to go away. It'll be replaced by a context popup for the new annotation,
// because the cursor will still be contained within it. Before it goes away, adjust
// the selection to make _sure_ that if the user just starts typing, it won't delete
// the entire link. We need to manually fiddle the selection a little, because
// annotations mean that the LinearSelection can't granularly say whether the
// selection starts inside or outside of the node.
// If you can think of a test function for "the selection has stabilised", this could
// be moved to ve.scheduler.
// Note: we can't rely on surfaceView.activeAnnotations, because the selection-focus created
// by the transaction might be outside the link node. As such, get the node immediately
// after the offset where we inserted the annotation, and then get the closest link
// annotation to it.
var node = surfaceView.getDocument().getNodeAndOffset( nodeRange.start + 1 ).node;
surfaceView.selectNodeContents( $( node ).closest( '.ve-ce-linkAnnotation' )[ 0 ] );
surfaceView.selectAnnotation( function ( view ) {
return view.model instanceof ve.dm.MWExternalLinkAnnotation;
} );
} );
} else {
surfaceModel.change(