Skip to content

Commit 90f3bde

Browse files
Highlight word when setting selection (#2751)
In vscode if you click on a word with the mouse corresponding words are highlighted. When using cursorless to set selection this doesn't happen on main. Fixes #2604 ## Checklist - [/] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [/] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [/] I have not broken the cheatsheet
1 parent 57acd6c commit 90f3bde

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

packages/common/src/types/TextEditor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export interface TextEditor {
5555
export interface SetSelectionsOpts {
5656
focusEditor?: boolean;
5757
revealRange?: boolean;
58+
highlightWord?: boolean;
5859
}
5960

6061
export type OpenLinkOptions = {

packages/cursorless-engine/src/actions/SetSelection.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ abstract class SetSelectionBase implements SimpleAction {
2121
? editor.selections.concat(targetSelections)
2222
: targetSelections;
2323

24+
const highlightWord =
25+
this.selectionMode === "set" &&
26+
selections.length === 1 &&
27+
selections[0].isEmpty;
28+
2429
await ide()
2530
.getEditableTextEditor(editor)
26-
.setSelections(selections, { focusEditor: true });
31+
.setSelections(selections, { focusEditor: true, highlightWord });
2732

2833
return {
2934
thatTargets: targets,

packages/cursorless-vscode/src/ide/vscode/VscodeTextEditorImpl.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ export class VscodeTextEditorImpl implements EditableTextEditor {
5151

5252
async setSelections(
5353
rawSelections: Selection[],
54-
{ focusEditor = false, revealRange = true }: SetSelectionsOpts = {},
54+
{
55+
focusEditor = false,
56+
revealRange = true,
57+
highlightWord = false,
58+
}: SetSelectionsOpts = {},
5559
): Promise<void> {
5660
const selections = uniqWithHash(
5761
rawSelections,
@@ -85,6 +89,10 @@ export class VscodeTextEditorImpl implements EditableTextEditor {
8589
if (revealRange) {
8690
await this.revealRange(this.selections[0]);
8791
}
92+
93+
if (highlightWord) {
94+
vscode.commands.executeCommand("editor.action.wordHighlight.trigger");
95+
}
8896
}
8997

9098
get visibleRanges(): Range[] {

0 commit comments

Comments
 (0)