Fix smartSelection returning extra span inside string quotes when cursor is outside them

This commit is contained in:
Andrew Branch 2019-06-14 15:50:09 -07:00
parent b6c415485a
commit 54f5f2baf2
No known key found for this signature in database
GPG key ID: 22CCA4B120C427D2
2 changed files with 16 additions and 2 deletions

View file

@ -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 dont contain the original position
textSpanIntersectsWithPosition(textSpan, pos)
)) {
selectionRange = { textSpan, ...selectionRange && { parent: selectionRange } };
}
}

View file

@ -0,0 +1,10 @@
const a = 'a';
const b = /**/'b';
'b'
const b = 'b';
const a = 'a';
const b = 'b';