Skip to content

Commit 4734033

Browse files
C-Loftuspre-commit-ci-lite[bot]pokey
authored
Keyboard cursor customization (#2443)
Addresses #2401, the ability to have custom cursor styling exclusively when in cursorless keyboard mode. Tried to follow the repo style as best as possible but please let me know if another way besides a record mapper is more idiomatic for TS. ## Checklist - [/] 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 could add docs in the visual a11y section but unclear if experimental keyboard support belongs there_ - [x] I have not broken the cheatsheet ## Example An image showing the cursor start out with a custom type, then change into `block` when keyboard mode is activated, thus adding more contrast. ![](https://github.com/cursorless-dev/cursorless/assets/70598503/b0dfd7bc-daa0-40bc-b052-20aed31c5d6e) --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Pokey Rule <[email protected]>
1 parent cb9da65 commit 4734033

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

packages/cursorless-vscode/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,19 @@
861861
"description": "Directory containing snippets for use in Cursorless",
862862
"type": "string"
863863
},
864+
"cursorless.experimental.keyboard.modal.cursorStyle": {
865+
"description": "Controls cursor style when in Cursorless keyboard mode",
866+
"type": "string",
867+
"enum": [
868+
"line",
869+
"block",
870+
"underline",
871+
"line-thin",
872+
"block-outline",
873+
"underline-thin"
874+
],
875+
"default": "block-outline"
876+
},
864877
"cursorless.experimental.keyboard.modal.keybindings.action": {
865878
"description": "Define modal keybindings for actions",
866879
"type": "object",

packages/cursorless-vscode/src/keyboard/KeyboardCommandsModal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export default class KeyboardCommandsModal {
120120
this.inputDisposable = this.keyboardHandler.pushListener({
121121
handleInput: this.handleInput,
122122
displayOptions: {
123-
cursorStyle: vscode.TextEditorCursorStyle.BlockOutline,
123+
cursorStyle: this.keyboardConfig.getCursorStyle(),
124124
whenClauseContext: "cursorless.keyboard.modal.mode",
125125
statusBarText: "Listening...",
126126
},

packages/cursorless-vscode/src/keyboard/KeyboardConfig.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { mapValues, pickBy } from "lodash";
22
import { KeyMap, SectionName, TokenType } from "./TokenTypeHelpers";
33
import { SectionTypes, TokenTypeValueMap } from "./TokenTypes";
44
import { VscodeApi } from "@cursorless/vscode-common";
5+
import { TextEditorCursorStyle } from "vscode";
56

67
const LEGACY_PLURAL_SECTION_NAMES: Record<string, string> = {
78
action: "actions",
@@ -11,9 +12,34 @@ const LEGACY_PLURAL_SECTION_NAMES: Record<string, string> = {
1112
scope: "scopes",
1213
};
1314

15+
/**
16+
* Maps from the raw cursor style config value to the corresponding
17+
* TextEditorCursorStyle enum value.
18+
*/
19+
const cursorStyleMap = {
20+
line: TextEditorCursorStyle.Line,
21+
block: TextEditorCursorStyle.Block,
22+
underline: TextEditorCursorStyle.Underline,
23+
["line-thin"]: TextEditorCursorStyle.LineThin,
24+
["block-outline"]: TextEditorCursorStyle.BlockOutline,
25+
["underline-thin"]: TextEditorCursorStyle.UnderlineThin,
26+
} satisfies Record<string, TextEditorCursorStyle>;
27+
1428
export class KeyboardConfig {
1529
constructor(private vscodeApi: VscodeApi) {}
1630

31+
getCursorStyle(): TextEditorCursorStyle {
32+
const rawCursorStyle = this.vscodeApi.workspace
33+
.getConfiguration("cursorless.experimental.keyboard.modal")
34+
.get<keyof typeof cursorStyleMap>("cursorStyle");
35+
36+
if (rawCursorStyle == null) {
37+
return TextEditorCursorStyle.BlockOutline;
38+
}
39+
40+
return cursorStyleMap[rawCursorStyle];
41+
}
42+
1743
/**
1844
* Returns a keymap for a given config section that is intended to be further
1945
* processed by eg {@link getSectionEntries} or {@link getSingularSectionEntry}.

0 commit comments

Comments
 (0)