diff --git a/src/services/smartSelection.ts b/src/services/smartSelection.ts index 3765c39ed7a..0a2adcd9507 100644 --- a/src/services/smartSelection.ts +++ b/src/services/smartSelection.ts @@ -17,7 +17,7 @@ namespace ts.SmartSelectionRange { break outer; } - if (positionShouldSnapToNode(pos, node, nextNode)) { + if (positionShouldSnapToNode(sourceFile, pos, node)) { // 1. Blocks are effectively redundant with SyntaxLists. // 2. TemplateSpans, along with the SyntaxLists containing them, are a somewhat unintuitive grouping // of things that should be considered independently. @@ -97,12 +97,11 @@ namespace ts.SmartSelectionRange { * count too, unless that position belongs to the next node. In effect, makes * selections able to snap to preceding tokens when the cursor is on the tail * end of them with only whitespace ahead. + * @param sourceFile The source file containing the nodes. * @param pos The position to check. * @param node The candidate node to snap to. - * @param nextNode The next sibling node in the tree. - * @param sourceFile The source file containing the nodes. */ - function positionShouldSnapToNode(pos: number, node: Node, nextNode: Node | undefined) { + function positionShouldSnapToNode(sourceFile: SourceFile, pos: number, node: Node) { // Can’t use 'ts.positionBelongsToNode()' here because it cleverly accounts // for missing nodes, which can’t really be considered when deciding what // to select. @@ -111,9 +110,8 @@ namespace ts.SmartSelectionRange { return true; } const nodeEnd = node.getEnd(); - const nextNodeStart = nextNode && nextNode.getStart(); if (nodeEnd === pos) { - return pos !== nextNodeStart; + return getTouchingPropertyName(sourceFile, pos).pos < node.end; } return false; } diff --git a/tests/baselines/reference/smartSelection_emptyRanges.baseline b/tests/baselines/reference/smartSelection_emptyRanges.baseline index 8ec58d839ab..efcb6e66ee9 100644 --- a/tests/baselines/reference/smartSelection_emptyRanges.baseline +++ b/tests/baselines/reference/smartSelection_emptyRanges.baseline @@ -44,7 +44,10 @@ class HomePage { } - ) + username + + + this.props.username if (this.props.username) { diff --git a/tests/baselines/reference/smartSelection_punctuationPriority.baseline b/tests/baselines/reference/smartSelection_punctuationPriority.baseline new file mode 100644 index 00000000000..176327b8c98 --- /dev/null +++ b/tests/baselines/reference/smartSelection_punctuationPriority.baseline @@ -0,0 +1,6 @@ +console/**/.log(); + +console +console.log +console.log() +console.log(); \ No newline at end of file diff --git a/tests/cases/fourslash/smartSelection_punctuationPriority.ts b/tests/cases/fourslash/smartSelection_punctuationPriority.ts new file mode 100644 index 00000000000..af841444b48 --- /dev/null +++ b/tests/cases/fourslash/smartSelection_punctuationPriority.ts @@ -0,0 +1,5 @@ +/// + +////console/**/.log(); + +verify.baselineSmartSelection();