Skip to content
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
1 change: 1 addition & 0 deletions packages/common/src/types/TextEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface TextEditor {
export interface SetSelectionsOpts {
focusEditor?: boolean;
revealRange?: boolean;
highlightWord?: boolean;
}

export type OpenLinkOptions = {
Expand Down
7 changes: 6 additions & 1 deletion packages/cursorless-engine/src/actions/SetSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ abstract class SetSelectionBase implements SimpleAction {
? editor.selections.concat(targetSelections)
: targetSelections;

const highlightWord =
this.selectionMode === "set" &&
selections.length === 1 &&
selections[0].isEmpty;

await ide()
.getEditableTextEditor(editor)
.setSelections(selections, { focusEditor: true });
.setSelections(selections, { focusEditor: true, highlightWord });

return {
thatTargets: targets,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export class VscodeTextEditorImpl implements EditableTextEditor {

async setSelections(
rawSelections: Selection[],
{ focusEditor = false, revealRange = true }: SetSelectionsOpts = {},
{
focusEditor = false,
revealRange = true,
highlightWord = false,
}: SetSelectionsOpts = {},
): Promise<void> {
const selections = uniqWithHash(
rawSelections,
Expand Down Expand Up @@ -85,6 +89,10 @@ export class VscodeTextEditorImpl implements EditableTextEditor {
if (revealRange) {
await this.revealRange(this.selections[0]);
}

if (highlightWord) {
vscode.commands.executeCommand("editor.action.wordHighlight.trigger");
}
}

get visibleRanges(): Range[] {
Expand Down
Loading