Skip to content

feat: add custom key mapping system#118

Open
ryanbbrown wants to merge 6 commits intopolyipseity:mainfrom
ryanbbrown:main
Open

feat: add custom key mapping system#118
ryanbbrown wants to merge 6 commits intopolyipseity:mainfrom
ryanbbrown:main

Conversation

@ryanbbrown
Copy link
Copy Markdown

@ryanbbrown ryanbbrown commented Mar 3, 2026

Summary

  • Adds custom key mappings: users define key combos and what the terminal sends (ignore, escape sequence, hex code, or text)
  • Includes a "Natural Text Editing (iTerm2)" preset that maps common macOS text navigation shortcuts (⌥/⌘ + arrows, backspace, delete) with one click
  • Fixes bug where two attachCustomKeyEventHandler calls silently overwrote each other (Shift+Enter handler was lost by the macOS Option key handler). All key interception is now consolidated into a single KeyMappingAddon.

Key mapping preset: Natural Text Editing

Shortcut Action
⌥← Word backward
⌥→ Word forward
⌘← Beginning of line
⌘→ End of line
⌥⌫ Delete word backward
⌘⌫ Delete to beginning of line
⌥Delete Delete word forward

🤖 Generated with Claude Code

ryanbbrown and others added 6 commits March 3, 2026 12:15
iTerm2-style key remapping: users define key combos and what the terminal
sends when pressed (ignore, escape sequence, hex code, or text).

Also fixes a bug where xterm.js only supports one
attachCustomKeyEventHandler but the codebase registered two (Shift+Enter
and macOS Option key), with the second silently overwriting the first.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix #isDisposed being set to false instead of true in
MacOSOptionKeyPassthroughAddon.dispose(). Also use Settings.KeyMapping
directly instead of a duplicate local interface, and simplify
formatShortcut with filter+join.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds an iTerm2-style preset to the key mapping modal that maps common
macOS text navigation shortcuts (Option/Cmd + arrows, backspace, delete).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ryanbbrown
Copy link
Copy Markdown
Author

Hey! Just bumping this, wondering if it might get a review at some point? Happy to make any revisions needed. I've been using this feature daily in my own setup and it's been working well, I think custom key mappings would be a nice addition to the plugin.

@janah01 janah01 self-requested a review March 19, 2026 02:58
@janah01
Copy link
Copy Markdown
Collaborator

janah01 commented Mar 19, 2026

Hey @ryanbbrown, thanks for taking the time to contribute this PR. Let me go through each point:

  1. attachCustomKeyEventHandler overwrite bug

This was already fixed on main in commit e023673, which consolidated Shift+Enter and macOS Option-key handling into a single CustomKeyEventHandlerAddon. There is now only one attachCustomKeyEventHandler call in the codebase, so I think this part of the PR is no longer needed.

  1. Natural Text Editing preset

Four of the seven bindings in the preset are already shipped on main from the same commit: ⌥← / ⌥→ for word navigation, and ⌥⌫ / ⌥Delete for word deletion. What was overlooked were the combos: ⌘← / ⌘→ for beginning/end of line, and ⌘⌫ for delete to beginning of line. Those are really needed.

That said, I don't think these seven key mappings should be a loadable preset. Every macOS terminal user expects / + Arrow / Backspace etc .. to just work. They are really baseline terminal UX on macOS. The plugin already treats macOS key handling as its responsibility (macOptionIsMeta forced off, platform-gated addon, hardcoded macOS Option-key handling), so these belong in the same category.

  1. Configurable key mapping system

The concept is genuinely useful for user-defined bindings beyond the standard set, but I think it needs its own follow-up issue/PR. A few things need to be considered first:

  • In its current form, user mappings run before the existing guard, which means the duplicated bindings in the preset would bypass the macOSOptionKeyPassthrough toggle.
  • keyMappings needs runtime platform gating. The plugin syncs settings globally and gates at runtime, same as macOSOptionKeyPassthrough, so e.g. mappings should not activate on Linux or Windows, where Meta+Arrow has OS-level meaning.
  • The bindings should also be independent of the macOSOptionKeyPassthrough toggle. That setting gates Option-key passthrough, not Command-key shortcuts.

This would also require an architectural decision: one suggestions could be one key-event router with a priority pipeline (invariant rules -> input compatibility -> user custom bindings -> platform defaults -> xterm fallthrough), persisting only deltas instead of full binding sets.

What I’d suggest for this PR is rebasing onto current main and slimming it down to just the three bindings inside the existing CustomKeyEventHandlerAddon, with the same macOS platform gate but independent of the Option passthrough toggle. Since this particular fix is really needed, I can help push the changes directly and merge your PR.

For the user-configurable mapping system, I suggest you open an issue or a follow up PR.

Let me know if you have questions, we can discuss further.

@janah01 janah01 added question Further information is requested bug Something isn't working good first issue Good for newcomers labels Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working good first issue Good for newcomers question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants