Skip to content

Configurable keyboard shortcuts that don't collide with the terminal or the browser #214

Closed

Description

@devswha

Problem

People who live in a terminal drive it from the keyboard, and they bring muscle memory from their terminal and multiplexer. herdr web ui has seven fixed app shortcuts, all Mod+Shift+key (src/lib/shortcuts.ts). Settings shows them as a read-only table. You can't change them, turn them off, or hand them to the program in the pane. Some of them already collide:

  1. Pane switching leaks into the terminal. In the terminal lens, Ctrl+Shift+↓ switches from pane A to pane B, and pane B's program also receives ESC[1;6B. Ctrl+Shift+↑ sends ESC[1;6A the same way.
    • Reproduced against an isolated test herdr session in headless Chrome, with xterm.js 5.5.0.
    • useShortcuts handles the key in a window capture listener that only calls preventDefault(). xterm.js doesn't check defaultPrevented, so it still encodes the key.
    • By then React has re-rendered, so the sequence reaches the pane you switched to.
  2. New session (Mod+Shift+N) never reaches the page in a Chrome tab.
    • Chrome reserves Ctrl+Shift+N for New Incognito Window: IDC_NEW_INCOGNITO_WINDOW in IsReservedCommandOrKey.
    • Only the installed app window gets the key, because there "no keys are reserved".
    • macOS Chrome should behave the same way with Cmd+Shift+N, but that is not verified here.
  3. Text selection in the composer on macOS. On macOS, Cmd+Shift+↑/↓ selects to the start or end of the text. The capture listener also takes it in the message box, and switches panes instead. This comes from reading the code; it was not run on a Mac.
  4. herdr's own keymap doesn't carry over.
    • herdr's TUI uses a prefix (ctrl+b by default) plus a fully configurable [keys] table in config.toml.
    • The web UI attaches one terminal at a time with herdr terminal attach. So prefix+… means nothing here, and ctrl+b goes to the shell.
    • The socket API has no method that reads [keys].

How herdr handles it (Keyboard, Keybindings, v0.9.3):

  • The defaults are prefix-first, so herdr doesn't steal keys from shells, editors or other terminal apps.
  • Every action can be rebound, including the prefix.
  • An array gives one action several chords.
  • [[keys.command]] binds custom commands.
  • herdr config reset-keys restores the defaults.
  • For direct, prefix-free chords, herdr recommends ctrl+alt+…, and lists the ctrl+alt chords to avoid. It chose this family after mapping the default keybindings of Ghostty, iTerm2, Terminal.app, kitty, WezTerm, Alacritty, Warp, Windows Terminal, GNOME Terminal and Konsole, plus the global shortcuts of GNOME and KDE.

How other terminals handle it. These are the patterns worth taking (the full comparison is below):

  • One changeable modifier: kitty's kitty_mod (default ctrl+shift), JupyterLab's Accel.
  • "Unbind" and "ignore" are different actions. Unbind hands the key to the program; ignore drops it. Examples: kitty (map with no action), Ghostty (unbind / ignore), Windows Terminal ("unbound"), Alacritty (ReceiveChar / None). VS Code's terminal makes the same choice with commandsToSkipShell and sendKeybindingsToShell.
  • Store only overrides of the defaults. VS Code uses -command rules; zellij uses unbind and clear-defaults.
  • Warn about conflicts while a key is being recorded. The VS Code and JupyterLab keybinding editors do this. For a web app, that also means keys the browser reserves in a tab.
  • Changing colliding defaults is normal. zellij 0.41 added a non-colliding "unlock-first" preset after users reported collisions with vim and emacs (zellij#1399).
Comparison: terminals, multiplexers and web terminals
Tool Config Example binding Unbind (key goes to the program) GUI editor Chords / leader
kitty kitty.conf map kitty_mod+c copy_to_clipboard (kitty_mod = ctrl+shift) map <key> with no action; discard_event; clear_all_shortcuts No map ctrl+f>2 …, modes
WezTerm Lua config.keys {key='m', mods='CMD', action=act.DisableDefaultAssignment} DisableDefaultAssignment, disable_default_key_bindings No LEADER, key tables
Alacritty TOML [keyboard] bindings { key = "N", mods = "Control|Shift", action = "CreateNewWindow" } ReceiveChar (to the program), None (dropped) No No
Ghostty keybind = trigger=action keybind = performable:ctrl+c=copy_to_clipboard unbind, ignore, keybind=clear No ctrl+a>n=…, key tables
Windows Terminal settings.json actions { "keys": "ctrl+shift+c", "id": "Terminal.CopyToClipboard" } "id": "unbound" / null Yes No (open request)
iTerm2 GUI Cmd-based defaults Ignore, Send Escape Sequence, delete Yes (only way) Leader key
GNOME Terminal gsettings copy = <Control><Shift>c Backspace in the editor; shortcuts-enabled Yes No
Konsole KDE shortcuts + .keytab Copy = Ctrl+Shift+C KDE editor Yes —
VS Code terminal keybindings.json + when { "key": "ctrl+k ctrl+w", "command": "…" } -command; commandsToSkipShell; sendKeybindingsToShell Yes, with conflict view Chords
tmux bind-key / key tables set -g prefix C-a, unbind C-b unbind; prefix twice sends it through No Prefix C-b, key tables
zellij KDL keybinds per mode bind "Ctrl g" { SwitchToMode "locked"; } unbind, clear-defaults, Locked mode Runtime config screen Modes; unlock-first preset
herdr config.toml [keys] next_tab = ["prefix+n", "ctrl+alt+]"] Unset optional actions; reset-keys No (prefix+? help lists them) Prefix ctrl+b

Browser constraints

  • Chrome tab: Ctrl/Cmd+W, Ctrl+Shift+W, Ctrl+T, Ctrl+N, Ctrl+Shift+N, Ctrl+Shift+T, Ctrl+Tab and quit are reserved and never reach the page.
  • Chrome installed app (PWA) window: nothing is reserved, and the page decides with preventDefault.
  • Firefox: Ctrl+N, Ctrl+T, Ctrl+W, Ctrl+Shift+W, Ctrl+Shift+P and quit are reserved.
  • Other web terminals:
    • code-server tells users to install the PWA for this reason, and vscode.dev documents the keys that don't work.
    • GoTTY (hterm) can mark a key "PASS" to hand it to the browser.
    • JupyterLab has a shortcut editor with conflict warnings, scoped by CSS selector.
  • Keyboard Lock (navigator.keyboard.lock()) works only in JS-requested fullscreen in Chromium, so it doesn't help a normal window.

Sources: kitty, WezTerm, Alacritty, Ghostty, Windows Terminal, iTerm2, GNOME Terminal, Konsole, VS Code keybindings, VS Code terminal, tmux, zellij presets, zellij bindings, Firefox reserved keys, code-server FAQ, vscode.dev keys, GoTTY, JupyterLab, Keyboard Lock.

Proposal

Phase 0: a bug fix, in its own PR. Stop app shortcuts from reaching xterm by also claiming them in attachCustomKeyEventHandler. Leave Mod+Shift+↑/↓ alone inside text fields.

Phase 1: configurable shortcuts.

  • Storage. Overrides live in settings, keyed by ShortcutId. Each override is an array of chords, and an empty array turns the shortcut off. Only overrides are stored, so changed defaults still reach everyone else.
  • Key syntax. Key strings use herdr's syntax (ctrl+shift+k, cmd+k, alt+1, minus, comma), so a chord can be copied between herdr's config.toml and the web UI.
  • Editing. The Settings shortcut table becomes editable: click a row, then press the keys. Reset is available per row and for all.
  • Conflict warnings. Warn when the chord collides with any of these:
    • another app shortcut;
    • a key the browser reserves in a tab (and say that the installed app does get it);
    • a key that terminal programs rely on (Ctrl+C, Ctrl+W, …).
  • Unbind vs off. Each shortcut gets a "send to terminal instead" choice for the terminal lens.

Open questions

  • Should New session move off Mod+Shift+N by default, since a Chrome tab can't receive it?
  • Should herdr's ctrl+alt+… family be offered as a preset for terminal-heavy users?
  • Should the server read the local PC's ~/.config/herdr/config.toml [keys] and suggest the same chords for matching actions (goto → palette, toggle_sidebar, new_workspace → New session)? Limits:
    • it would not cover remote PCs;
    • prefix bindings have no web equivalent.
  • Should the web UI get a prefix or leader mode? It must not default to ctrl+b, which belongs to herdr and to the programs in the pane.
  • Which other actions are worth binding? Candidates: focus the composer, pane 1–9, Stop, the session panel.

Where

Terminal · Sidebar and navigation · Chat and prompt cards

Workarounds and alternatives

  • New session: install the app (PWA); its window receives Ctrl/Cmd+Shift+N.
  • The leaked ESC[1;6A / ESC[1;6B: there is no workaround except switching panes from the sidebar while in the terminal lens.

Activity

  1. added
    enhancement
    on Sep 30, 2026
  2. devswha commented on Oct 2, 2026

    @devswha
    OwnerAuthor

    Checked the bugs listed here on main, in headless Chrome against an isolated herdr session:

    1. Pane switching leaking ESC[1;6B into the terminal: fixed earlier by fix(terminal): app shortcuts no longer type into the pane #215. Ctrl+Shift+↓ in pane A's terminal switches to pane B and neither pane receives anything.
    2. New session never reaching the page in a Chrome tab: fix(shortcuts): leave Mod+Shift+arrows to text fields, and open New session with Mod+Shift+O #298 adds Mod+Shift+O, which a tab passes; Mod+Shift+N still works in the installed app.
    3. Cmd+Shift+↑/↓ taken from the message box on a Mac: reproduced, and fixed by fix(shortcuts): leave Mod+Shift+arrows to text fields, and open New session with Mod+Shift+O #298: in a text field those keys stay the field's.

    Not checked: a real Mac, and a real Chrome tab's reserved keys.

    Item 4 and the proposal itself (shortcuts the user can change, herdr's keymap carried over) are still open, so this issue stays open for them.

  3. devswha commented on Oct 3, 2026

    @devswha
    OwnerAuthor

    Closing: what this issue asked for is released.

    Not done: item 4, carrying herdr's own [keys] table and prefix over to the web UI. herdr's socket API has no method that reads [keys], so there is nothing to build on yet. If that becomes possible, it is worth its own issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions