Skip to content

Commit b98e9c7

Browse files
committed
Add toggleTabFocusMode and temporarilySetTabFocusMode commands
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`.
1 parent 4d54506 commit b98e9c7

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"dependencies": {
2929
"@codemirror/language": "^6.0.0",
3030
"@codemirror/state": "^6.4.0",
31-
"@codemirror/view": "^6.0.0",
31+
"@codemirror/view": "^6.27.0",
3232
"@lezer/common": "^1.1.0"
3333
},
3434
"devDependencies": {

src/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,9 @@ with key bindings for a lot of them.
234234
@blockUncomment
235235

236236
@toggleBlockCommentByLine
237+
238+
### Tab Focus Mode
239+
240+
@toggleTabFocusMode
241+
242+
@temporarilySetTabFocusMode

src/commands.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,24 @@ export const indentLess: StateCommand = ({state, dispatch}) => {
825825
return true
826826
}
827827

828+
/// Enables or disables
829+
/// [tab-focus mode](#view.EditorView.setTabFocusMode). While on, this
830+
/// prevents the editor's key bindings from capturing Tab or
831+
/// Shift-Tab, making it possible for the user to move focus out of
832+
/// the editor with the keyboard.
833+
export const toggleTabFocusMode: Command = view => {
834+
view.setTabFocusMode()
835+
return true
836+
}
837+
838+
/// Temporarily enables [tab-focus
839+
/// mode](#view.EditorView.setTabFocusMode) for two seconds or until
840+
/// another key is pressed.
841+
export const temporarilySetTabFocusMode: Command = view => {
842+
view.setTabFocusMode(2000)
843+
return true
844+
}
845+
828846
/// Insert a tab character at the cursor or, if something is selected,
829847
/// use [`indentMore`](#commands.indentMore) to indent the entire
830848
/// selection.
@@ -961,6 +979,7 @@ export const standardKeymap: readonly KeyBinding[] = ([
961979
/// - Shift-Ctrl-\\ (Shift-Cmd-\\ on macOS): [`cursorMatchingBracket`](#commands.cursorMatchingBracket)
962980
/// - Ctrl-/ (Cmd-/ on macOS): [`toggleComment`](#commands.toggleComment).
963981
/// - Shift-Alt-a: [`toggleBlockComment`](#commands.toggleBlockComment).
982+
/// - Ctrl-m (Alt-Shift-m on macOS): [`toggleTabFocusMode`](#commands.toggleTabFocusMode).
964983
export const defaultKeymap: readonly KeyBinding[] = ([
965984
{key: "Alt-ArrowLeft", mac: "Ctrl-ArrowLeft", run: cursorSyntaxLeft, shift: selectSyntaxLeft},
966985
{key: "Alt-ArrowRight", mac: "Ctrl-ArrowRight", run: cursorSyntaxRight, shift: selectSyntaxRight},
@@ -986,7 +1005,9 @@ export const defaultKeymap: readonly KeyBinding[] = ([
9861005
{key: "Shift-Mod-\\", run: cursorMatchingBracket},
9871006

9881007
{key: "Mod-/", run: toggleComment},
989-
{key: "Alt-A", run: toggleBlockComment}
1008+
{key: "Alt-A", run: toggleBlockComment},
1009+
1010+
{key: "Ctrl-m", mac: "Shift-Alt-m", run: toggleTabFocusMode},
9901011
] as readonly KeyBinding[]).concat(standardKeymap)
9911012

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

0 commit comments

Comments
 (0)