Skip to content

Commit

Permalink
Add toggleTabFocusMode and temporarilySetTabFocusMode commands
Browse files Browse the repository at this point in the history
FEATURE: The new `toggleTabFocusMode` and `temporarilySetTabFocusMode`
commands provide control over the view's tab-focus mode.

FEATURE: The default keymap now binds Ctrl-m (Shift-Alt-m on macOS) to
`toggleTabFocusMode`.
  • Loading branch information
marijnh committed Jun 4, 2024
1 parent 4d54506 commit b98e9c7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dependencies": {
"@codemirror/language": "^6.0.0",
"@codemirror/state": "^6.4.0",
"@codemirror/view": "^6.0.0",
"@codemirror/view": "^6.27.0",
"@lezer/common": "^1.1.0"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,9 @@ with key bindings for a lot of them.
@blockUncomment

@toggleBlockCommentByLine

### Tab Focus Mode

@toggleTabFocusMode

@temporarilySetTabFocusMode
23 changes: 22 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,24 @@ export const indentLess: StateCommand = ({state, dispatch}) => {
return true
}

/// Enables or disables
/// [tab-focus mode](#view.EditorView.setTabFocusMode). While on, this
/// prevents the editor's key bindings from capturing Tab or
/// Shift-Tab, making it possible for the user to move focus out of
/// the editor with the keyboard.
export const toggleTabFocusMode: Command = view => {
view.setTabFocusMode()
return true
}

/// Temporarily enables [tab-focus
/// mode](#view.EditorView.setTabFocusMode) for two seconds or until
/// another key is pressed.
export const temporarilySetTabFocusMode: Command = view => {
view.setTabFocusMode(2000)
return true
}

/// Insert a tab character at the cursor or, if something is selected,
/// use [`indentMore`](#commands.indentMore) to indent the entire
/// selection.
Expand Down Expand Up @@ -961,6 +979,7 @@ export const standardKeymap: readonly KeyBinding[] = ([
/// - Shift-Ctrl-\\ (Shift-Cmd-\\ on macOS): [`cursorMatchingBracket`](#commands.cursorMatchingBracket)
/// - Ctrl-/ (Cmd-/ on macOS): [`toggleComment`](#commands.toggleComment).
/// - Shift-Alt-a: [`toggleBlockComment`](#commands.toggleBlockComment).
/// - Ctrl-m (Alt-Shift-m on macOS): [`toggleTabFocusMode`](#commands.toggleTabFocusMode).
export const defaultKeymap: readonly KeyBinding[] = ([
{key: "Alt-ArrowLeft", mac: "Ctrl-ArrowLeft", run: cursorSyntaxLeft, shift: selectSyntaxLeft},
{key: "Alt-ArrowRight", mac: "Ctrl-ArrowRight", run: cursorSyntaxRight, shift: selectSyntaxRight},
Expand All @@ -986,7 +1005,9 @@ export const defaultKeymap: readonly KeyBinding[] = ([
{key: "Shift-Mod-\\", run: cursorMatchingBracket},

{key: "Mod-/", run: toggleComment},
{key: "Alt-A", run: toggleBlockComment}
{key: "Alt-A", run: toggleBlockComment},

{key: "Ctrl-m", mac: "Shift-Alt-m", run: toggleTabFocusMode},
] as readonly KeyBinding[]).concat(standardKeymap)

/// A binding that binds Tab to [`indentMore`](#commands.indentMore) and
Expand Down

0 comments on commit b98e9c7

Please sign in to comment.