Skip to content

fix: enable Option+Backspace word deletion in terminal#349

Open
AndresGonzalez5 wants to merge 1 commit intoalltuner:mainfrom
AndresGonzalez5:fix/option-backspace-word-deletion
Open

fix: enable Option+Backspace word deletion in terminal#349
AndresGonzalez5 wants to merge 1 commit intoalltuner:mainfrom
AndresGonzalez5:fix/option-backspace-word-deletion

Conversation

@AndresGonzalez5
Copy link
Copy Markdown

Summary

  • Option+Backspace (delete word) doesn't work in Factory Floor's embedded terminal — it produces a composed special character instead of sending ESC+DEL
  • Configures Ghostty's macos-option-as-alt = left so the left Option key acts as Alt/Meta
  • Right Option remains the macOS compose key for accented characters (ñ, ü, etc.)
  • Adds proper modifier translation in keyDown using Ghostty's ghostty_surface_key_translation_mods API, so interpretKeyEvents sees the base character
  • Adds sided modifier detection (NX_DEVICE* masks) to distinguish left vs right Option

Changes

  • TerminalApp.swift: Loads macos-option-as-alt = left config into Ghostty at init
  • TerminalView.swift: Translates modifier flags before interpretKeyEvents using Ghostty's translation API; adds sided modifier detection and ghosttyModsToFlags reverse helper

Test plan

  • Open a terminal tab and press Option+Backspace — should delete the previous word
  • Press Option+Left/Right arrow — should jump word-by-word
  • Press Right Option+e, then a — should produce á (compose key still works)
  • Press Right Option+n, then n — should produce ñ
  • Verify IME / dead key input (e.g., Japanese, Korean) still works correctly

🤖 Generated with Claude Code

Left Option key now acts as Alt/Meta in the embedded Ghostty terminal,
so Option+Backspace sends ESC+DEL (delete word) instead of composing
a special character. Right Option remains the macOS compose key.

Changes:
- TerminalApp: loads `macos-option-as-alt = left` into Ghostty config
- TerminalView: uses `ghostty_surface_key_translation_mods` to translate
  modifier flags before `interpretKeyEvents`, so the text input system
  sees the base character rather than a composed one
- TerminalView: adds sided modifier detection (NX_DEVICE*) to
  `flagsToGhosttyMods` so Ghostty can distinguish left vs right Option
- TerminalView: adds `ghosttyModsToFlags` reverse helper

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@AndresGonzalez5
Copy link
Copy Markdown
Author

I always use left option instead of the one on the right, so I put = left, but feel free to modify it. I found the improvement useful :)

@davidpoblador
Copy link
Copy Markdown
Member

Thanks for the PR! A couple of questions before we move forward:

  1. Do you have Ghostty installed on your machine? Factory Floor's embedded terminals inherit your Ghostty config from ~/.config/ghostty/config. If you have macos-option-as-alt set there, it would already apply inside Factory Floor.

  2. Does Option+Backspace work for you in standalone Ghostty (or whichever terminal emulator you normally use)? Ghostty has a keyboard layout heuristic that auto-enables option-as-alt on US/US International layouts even without explicit config. If you're on a non-US layout, the default is off — which would explain the issue.

  3. What keyboard layout are you using? (US, Spanish, etc.)

Asking because this determines the right fix. One concern with the current approach: ghostty_config_load_file is called after ghostty_config_load_default_files, so it would override whatever the user has in their own Ghostty config for this setting. For example, someone with macos-option-as-alt = true would get silently downgraded to left.

@AndresGonzalez5
Copy link
Copy Markdown
Author

No problem! I've been playing with the project a bit to fit the specific AI workflow I already had with worktrees.

  1. I do have Ghostty and use it heavily. The only config besides keybindings and theme modification is the macos-option-as-alt. Once I started using FactoryFloor I noticed that it stopped working, so something must have overriden my configuration (hence the PR)
  2. Yes, it works in standalone terminal because I added that config line in my Ghostty settings
  3. I use a MacBook from the US, with the keyboard set to International US (to be able to write tildes in Spanish)

I also had to jump through some hoops in order to build the xcFramework in macOS Tahoe, if it makes any difference.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants