Skip to content

Commit

Permalink
Merge pull request microsoft#58989 from sbatten/fix/40658
Browse files Browse the repository at this point in the history
prioritize tokens over brackets in find
  • Loading branch information
rebornix authored Sep 21, 2018
2 parents c8381a5 + 505c761 commit 2558a72
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,44 @@ suite('TokenSelectionSupport', () => {
new Range(3, 1, 3, 2)
]);
});

test('getRangesToPosition #40658. Cursor at first position inside brackets should select line inside.', () => {

assertGetRangesToPosition([
' [ ]',
' { } ',
'( ) '
], 2, 3, [
new Range(1, 1, 3, 5),
new Range(2, 1, 2, 6),
new Range(2, 2, 2, 5),
new Range(2, 3, 2, 4)
]);
});

test('getRangesToPosition #40658. Cursor in empty brackets should reveal brackets first.', () => {

assertGetRangesToPosition([
' [] ',
' { } ',
' ( ) '
], 1, 3, [
new Range(1, 1, 3, 7),
new Range(1, 1, 1, 5),
new Range(1, 2, 1, 4)
]);
});

test('getRangesToPosition #40658. Tokens before bracket will be revealed first.', () => {

assertGetRangesToPosition([
' [] ',
' { } ',
'selectthis( ) '
], 3, 11, [
new Range(1, 1, 3, 15),
new Range(3, 1, 3, 15),
new Range(3, 1, 3, 11)
]);
});
});
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/smartSelect/tokenTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export function find(node: Node, position: Position): Node {
}

} else if (node instanceof Block) {
result = find(node.open, position) || find(node.elements, position) || find(node.close, position);
result = find(node.elements, position) || find(node.open, position) || find(node.close, position);
}

return result || node;
Expand Down

0 comments on commit 2558a72

Please sign in to comment.