From 54f5f2baf26cf247145026ecb8c63fe23b4aa578 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Fri, 14 Jun 2019 15:50:09 -0700 Subject: [PATCH] Fix smartSelection returning extra span inside string quotes when cursor is outside them --- src/services/smartSelection.ts | 8 ++++++-- .../reference/smartSelection_stringLiteral.baseline | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/smartSelection_stringLiteral.baseline diff --git a/src/services/smartSelection.ts b/src/services/smartSelection.ts index ddd3c75c2c..d0423ce031 100644 --- a/src/services/smartSelection.ts +++ b/src/services/smartSelection.ts @@ -72,9 +72,13 @@ namespace ts.SmartSelectionRange { function pushSelectionRange(start: number, end: number): void { // Skip empty ranges if (start !== end) { - // Skip ranges that are identical to the parent const textSpan = createTextSpanFromBounds(start, end); - if (!selectionRange || !textSpansEqual(textSpan, selectionRange.textSpan)) { + if (!selectionRange || ( + // Skip ranges that are identical to the parent + !textSpansEqual(textSpan, selectionRange.textSpan) && + // Skip ranges that don’t contain the original position + textSpanIntersectsWithPosition(textSpan, pos) + )) { selectionRange = { textSpan, ...selectionRange && { parent: selectionRange } }; } } diff --git a/tests/baselines/reference/smartSelection_stringLiteral.baseline b/tests/baselines/reference/smartSelection_stringLiteral.baseline new file mode 100644 index 0000000000..4e062d162c --- /dev/null +++ b/tests/baselines/reference/smartSelection_stringLiteral.baseline @@ -0,0 +1,10 @@ +const a = 'a'; +const b = /**/'b'; + + + 'b' + +const b = 'b'; + +const a = 'a'; +const b = 'b'; \ No newline at end of file