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

* Prioritize “property names” over punctuation in smart select

* Update doc comment
This commit is contained in:
Andrew Branch 2019-08-02 15:57:44 -07:00 committed by GitHub
parent e75972cbad
commit 725321f08c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 7 deletions

View File

@ -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) {
// Cant use 'ts.positionBelongsToNode()' here because it cleverly accounts
// for missing nodes, which cant 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;
}

View File

@ -44,7 +44,10 @@ class HomePage {
}
)
username
this.props.username
if (this.props.username) {

View File

@ -0,0 +1,6 @@
console/**/.log();
console
console.log
console.log()
console.log();

View File

@ -0,0 +1,5 @@
/// <reference path="fourslash.ts" />
////console/**/.log();
verify.baselineSmartSelection();