Skip to content

Commit

Permalink
Keyboard cursor customization (#2443)
Browse files Browse the repository at this point in the history
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 <755842+pokey@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 8, 2024
1 parent cb9da65 commit 4734033
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/cursorless-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,19 @@
"description": "Directory containing snippets for use in Cursorless",
"type": "string"
},
"cursorless.experimental.keyboard.modal.cursorStyle": {
"description": "Controls cursor style when in Cursorless keyboard mode",
"type": "string",
"enum": [
"line",
"block",
"underline",
"line-thin",
"block-outline",
"underline-thin"
],
"default": "block-outline"
},
"cursorless.experimental.keyboard.modal.keybindings.action": {
"description": "Define modal keybindings for actions",
"type": "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default class KeyboardCommandsModal {
this.inputDisposable = this.keyboardHandler.pushListener({
handleInput: this.handleInput,
displayOptions: {
cursorStyle: vscode.TextEditorCursorStyle.BlockOutline,
cursorStyle: this.keyboardConfig.getCursorStyle(),
whenClauseContext: "cursorless.keyboard.modal.mode",
statusBarText: "Listening...",
},
Expand Down
26 changes: 26 additions & 0 deletions packages/cursorless-vscode/src/keyboard/KeyboardConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mapValues, pickBy } from "lodash";
import { KeyMap, SectionName, TokenType } from "./TokenTypeHelpers";
import { SectionTypes, TokenTypeValueMap } from "./TokenTypes";
import { VscodeApi } from "@cursorless/vscode-common";
import { TextEditorCursorStyle } from "vscode";

const LEGACY_PLURAL_SECTION_NAMES: Record<string, string> = {
action: "actions",
Expand All @@ -11,9 +12,34 @@ const LEGACY_PLURAL_SECTION_NAMES: Record<string, string> = {
scope: "scopes",
};

/**
* Maps from the raw cursor style config value to the corresponding
* TextEditorCursorStyle enum value.
*/
const cursorStyleMap = {
line: TextEditorCursorStyle.Line,
block: TextEditorCursorStyle.Block,
underline: TextEditorCursorStyle.Underline,
["line-thin"]: TextEditorCursorStyle.LineThin,
["block-outline"]: TextEditorCursorStyle.BlockOutline,
["underline-thin"]: TextEditorCursorStyle.UnderlineThin,
} satisfies Record<string, TextEditorCursorStyle>;

export class KeyboardConfig {
constructor(private vscodeApi: VscodeApi) {}

getCursorStyle(): TextEditorCursorStyle {
const rawCursorStyle = this.vscodeApi.workspace
.getConfiguration("cursorless.experimental.keyboard.modal")
.get<keyof typeof cursorStyleMap>("cursorStyle");

if (rawCursorStyle == null) {
return TextEditorCursorStyle.BlockOutline;
}

return cursorStyleMap[rawCursorStyle];
}

/**
* Returns a keymap for a given config section that is intended to be further
* processed by eg {@link getSectionEntries} or {@link getSingularSectionEntry}.
Expand Down

0 comments on commit 4734033

Please sign in to comment.