Skip to content

Commit 54f5f2b

Browse files
committed
Fix smartSelection returning extra span inside string quotes when cursor is outside them
1 parent b6c4154 commit 54f5f2b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/services/smartSelection.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,13 @@ namespace ts.SmartSelectionRange {
7272
function pushSelectionRange(start: number, end: number): void {
7373
// Skip empty ranges
7474
if (start !== end) {
75-
// Skip ranges that are identical to the parent
7675
const textSpan = createTextSpanFromBounds(start, end);
77-
if (!selectionRange || !textSpansEqual(textSpan, selectionRange.textSpan)) {
76+
if (!selectionRange || (
77+
// Skip ranges that are identical to the parent
78+
!textSpansEqual(textSpan, selectionRange.textSpan) &&
79+
// Skip ranges that don’t contain the original position
80+
textSpanIntersectsWithPosition(textSpan, pos)
81+
)) {
7882
selectionRange = { textSpan, ...selectionRange && { parent: selectionRange } };
7983
}
8084
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const a = 'a';
2+
const b = /**/'b';
3+
4+
5+
'b'
6+
7+
const b = 'b';
8+
9+
const a = 'a';
10+
const b = 'b';

0 commit comments

Comments
 (0)