Skip to content

Commit

Permalink
Fix #86441
Browse files Browse the repository at this point in the history
  • Loading branch information
octref committed Dec 6, 2019
1 parent 3986960 commit 06f97fe
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions extensions/html-language-features/client/src/mirrorCursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,30 @@ export function activateMirrorCursor(
}
}

const exitMirrorMode = () => {
inMirrorMode = false;
window.activeTextEditor!.selections = [window.activeTextEditor!.selections[0]];
};

if (cursors.length === 2 && inMirrorMode) {
// Check two cases
if (event.selections[0].isEmpty && event.selections[1].isEmpty) {
if (
prevCursors.length === 2 &&
event.selections[0].anchor.line !== prevCursors[0].anchor.line &&
event.selections[1].anchor.line !== prevCursors[0].anchor.line
) {
exitMirrorMode();
return;
}

const charBeforeAndAfterPositionsRoughtlyEqual = isCharBeforeAndAfterPositionsRoughtlyEqual(
event.textEditor.document,
event.selections[0].anchor,
event.selections[1].anchor
);

if (!charBeforeAndAfterPositionsRoughtlyEqual) {
inMirrorMode = false;
window.activeTextEditor!.selections = [window.activeTextEditor!.selections[0]];
exitMirrorMode();
return;
} else {
// Need to cleanup in the case of <div |></div |>
Expand All @@ -109,11 +121,10 @@ export function activateMirrorCursor(
event.selections[1].anchor
)
) {
inMirrorMode = false;
const cleanupEdit = new WorkspaceEdit();
const cleanupRange = new Range(event.selections[1].anchor.translate(0, -1), event.selections[1].anchor);
cleanupEdit.replace(event.textEditor.document.uri, cleanupRange, '');
window.activeTextEditor!.selections = [window.activeTextEditor!.selections[0]];
exitMirrorMode();
workspace.applyEdit(cleanupEdit);
}
}
Expand Down

0 comments on commit 06f97fe

Please sign in to comment.