Skip to content

Commit 6fc9fe3

Browse files
Allow toggle decorations to take a boolean argument (#2464)
```talon hats on: user.run_rpc_command("cursorless.toggleDecorations", true) hats off: user.run_rpc_command("cursorless.toggleDecorations", false) ``` Fixes #2462 ## Checklist - [x] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [x] 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 95ef93a commit 6fc9fe3

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

docs/user/customization.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ While the hats are hidden, you will not be able to address any marks, eg `"take
119119

120120
If you'd like to map a voice command to toggle the hats, have a look at https://youtu.be/oWUJyDgz63k
121121

122+
Using the command server you can also specify if the hats should be on or of with a true/false value
123+
124+
```talon
125+
hats on: user.run_rpc_command("cursorless.toggleDecorations", true)
126+
hats off: user.run_rpc_command("cursorless.toggleDecorations", false)
127+
```
128+
122129
## Updating word separators
123130

124131
The word separators are characters that defines the boundary between words in a identifier. eg `hello_world` is an identifier with two words separated by `_`. If you like to support other separators like `-` in `hello-world` that can be accomplished by changing the `cursorless.wordSeparators` setting. This setting is also language overridable.

packages/cursorless-vscode-e2e/src/suite/toggleDecorations.vscode.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,14 @@ async function runTest() {
2727
await vscode.commands.executeCommand("cursorless.toggleDecorations");
2828
await hatTokenMap.allocateHats();
2929
assert((await hatTokenMap.getReadableMap(false)).getEntries().length !== 0);
30+
31+
// Check that hats disappear when turned off
32+
await vscode.commands.executeCommand("cursorless.toggleDecorations", false);
33+
await hatTokenMap.allocateHats();
34+
assert((await hatTokenMap.getReadableMap(false)).getEntries().length === 0);
35+
36+
// Check that hats reappear when turned back on
37+
await vscode.commands.executeCommand("cursorless.toggleDecorations", true);
38+
await hatTokenMap.allocateHats();
39+
assert((await hatTokenMap.getReadableMap(false)).getEntries().length !== 0);
3040
}

packages/cursorless-vscode/src/ide/vscode/hats/VscodeHats.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ export class VscodeHats implements Hats {
5858
await this.hatRenderer.init();
5959
}
6060

61-
toggle() {
62-
this.isEnabled = !this.isEnabled;
61+
toggle(isEnabled?: boolean) {
62+
this.isEnabled = isEnabled ?? !this.isEnabled;
6363
this.isEnabledNotifier.notifyListeners(this.isEnabled);
6464
}
6565

0 commit comments

Comments
 (0)