#59

Input fields ignore Option+Backspace / Cmd+Backspace on macOS (word / line delete)

Openparzival1lopened 7mo ago

On macOS every native text field deletes the previous word on Option+Backspace and deletes to the start of the line on Cmd+Backspace. Every Input widget in ThreadHop ignores both — the chord falls through as a no-op and the user is stuck deleting one character at a time. Since ThreadHop is macOS-only (per the README's ps/lsof note) this is a papercut the platform users hit every time they want to retype a search or filter.

1. What happens today

Textual's Input widget ships one delete binding: backspace → delete_left. The actions the standard library already implements but does not bind are:

  • action_delete_left_word — delete the word before the caret
  • action_delete_left_all — delete everything before the caret (line-start)
  • action_delete_right_word / action_delete_right_all — the forward equivalents

So the capability exists; only the keymap is missing. On a US macOS terminal:

  • Option+Backspace emits ESC DEL (\x1b\x7f), which Textual exposes as the key name alt+backspace — unbound in Input by default.
  • Cmd+Backspace is usually swallowed by the terminal itself, but Terminal.app and iTerm2 let the user remap it to send Ctrl+U (\x15). ctrl+u is also unbound by default.
  • Option+Delete (forward) and Cmd+Delete (forward) have the same story on the right-delete side.

Net result: the only way to clear a search box is holding Backspace.

2. Affected surfaces

All inherit the same default bindings — fixing the base class fixes every site at once.

  • threadhop SearchScreen — #search-input (line ~2611)
  • threadhop BookmarkBrowserScreen — #bookmark-input (line ~3012)
  • threadhop LabelPromptScreen — #label-input (line ~3236)
  • threadhop FindBar — #find-input (line ~3500)
  • Transcript reply input in the main ClaudeSessions layout (same Input class)

3. Direction

Two reasonable shapes. Prefer the subclass — scoping the bindings to a ThreadHop-owned widget keeps the behaviour predictable if Textual changes its own defaults upstream.

Option A — subclass once, swap everywhere. Introduce a MacInput(Input) with a BINDINGS extension:

BINDINGS = [
    Binding(\"alt+backspace\", \"delete_left_word\", show=False),
    Binding(\"ctrl+w\",        \"delete_left_word\", show=False),  # readline parity
    Binding(\"ctrl+u\",        \"delete_left_all\",  show=False),  # Cmd+Backspace via terminal remap
    Binding(\"alt+delete\",    \"delete_right_word\", show=False),
    Binding(\"ctrl+k\",        \"delete_right_all\",  show=False),
]

Replace the four+1 Input(...) call sites with MacInput(...).

Option B — bind on each screen. Add the same keybinds screen by screen. Cheaper diff, but drifts the moment a new input surface lands.

Cmd+Backspace caveat

Cmd+<key> is owned by the terminal on macOS, not the TTY-connected app. We can honour it only when the user maps Cmd+Backspace → Ctrl+U in their terminal profile. That's a one-line docs note in INSTALL-MACOS.md ("For Cmd+Backspace to clear the line, add a keybinding in Terminal → Settings → Profiles → Keyboard sending \\x15."). Users who don't map it still get Option+Backspace word-delete, which covers the 80% case.

4. Action items

  • Add a MacInput(Input) (or equivalent) in threadhop with bindings for alt+backspace, ctrl+w, ctrl+u, alt+delete, ctrl+k
  • Swap the four+1 Input(...) call sites to the new class (search, bookmark filter, label prompt, find bar, transcript reply)
  • Verify on Terminal.app and iTerm2 that alt+backspace arrives as ESC DEL (default in both; no profile changes needed)
  • Document the Terminal / iTerm profile tweak for Cmd+Backspace → Ctrl+U in INSTALL-MACOS.md
  • Smoke test in each modal: type a multi-word query, word-delete back to empty, retype; confirm no stray \\x7f renders in the field

References

  • threadhop — the four Input(...) call sites listed in §2
  • Textual Input widget — action_delete_left_word, action_delete_left_all, action_delete_right_word, action_delete_right_all already exist upstream; only the default BINDINGS list omits them
  • INSTALL-MACOS.md — natural home for the Cmd+Backspace terminal-profile note
  • README's macOS-only scoping (ps/lsof session detection) — reason this papercut is 100% of users, not a subset

Activity

0

No activity yet.