Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prioritize “property names” over punctuation in smart select #32687

Merged
merged 2 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/services/smartSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ class HomePage {
}


)
username


this.props.username


if (this.props.username) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
console/**/.log();

console
console.log
console.log()
console.log();
5 changes: 5 additions & 0 deletions tests/cases/fourslash/smartSelection_punctuationPriority.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference path="fourslash.ts" />

////console/**/.log();

verify.baselineSmartSelection();