Skip to content

Commit a890275

Browse files
authored
Merge pull request microsoft#31912 from andrewbranch/bug/31657
Fix smartSelection returning extra span inside string quotes when cursor is outside them
2 parents af20e79 + 54f5f2b commit a890275

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-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';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//// const a = 'a';
4+
//// const b = /**/'b';
5+
6+
verify.baselineSmartSelection();

0 commit comments

Comments
 (0)