From 6debd159dfc987ce396fb1468f1750c7be084a48 Mon Sep 17 00:00:00 2001 From: Pine Wu Date: Tue, 17 Dec 2019 11:43:19 -0800 Subject: [PATCH] Add comment and improve mirror cursor exit logic --- .../client/src/mirrorCursor.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/extensions/html-language-features/client/src/mirrorCursor.ts b/extensions/html-language-features/client/src/mirrorCursor.ts index 4edf06bdc2b..3c7cca06ff4 100644 --- a/extensions/html-language-features/client/src/mirrorCursor.ts +++ b/extensions/html-language-features/client/src/mirrorCursor.ts @@ -93,6 +93,9 @@ export function activateMirrorCursor( }; if (cursors.length === 2 && inMirrorMode) { + /** + * Both cursors are positions + */ if (event.selections[0].isEmpty && event.selections[1].isEmpty) { if ( prevCursors.length === 2 && @@ -128,14 +131,24 @@ export function activateMirrorCursor( workspace.applyEdit(cleanupEdit); } } - } else { - const charBeforeAndAfterPositionsRoughlyEqual = isCharBeforeAndAfterPositionsRoughlyEqual( + } + /** + * Both cursors are selections + */ + else { + const charBeforeAndAfterAnchorPositionsRoughlyEqual = isCharBeforeAndAfterPositionsRoughlyEqual( + event.textEditor.document, + event.selections[0].anchor, + event.selections[1].anchor + ); + + const charBeforeAndAfterActivePositionsRoughlyEqual = isCharBeforeAndAfterPositionsRoughlyEqual( event.textEditor.document, event.selections[0].active, event.selections[1].active ); - if (!charBeforeAndAfterPositionsRoughlyEqual) { + if (!charBeforeAndAfterAnchorPositionsRoughlyEqual || !charBeforeAndAfterActivePositionsRoughlyEqual) { exitMirrorMode(); } } -- GitLab