Fix GlobalKeyMap matching for keyboards with layout-dependent charactersIgnoringModifiers#665
Open
TankTechnology wants to merge 2 commits into
Open
Conversation
Demonstrates that GlobalKeyMap key binding matching breaks when charactersIgnoringModifiers differs from the character stored in the plist binding. On Chinese/Pinyin keyboards the backtick key (`) returns different charactersIgnoringModifiers values depending on input method state (0xb7 vs 0x60), causing Cmd+` to become unrecognized after text input. The test mirrors iTermKeystroke.keyInBindingDictionary: logic and shows a portableSerialized fallback resolves the mismatch. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
When a keystroke's charactersIgnoringModifiers differs from what was recorded in the binding (common on Chinese/Pinyin keyboards where the backtick key returns different characters in different input modes), existing fallbacks fail because they all depend on the character field. Add a portableSerialized (*-modifiers-keycode) fallback that matches on virtual key code and modifiers only, ignoring the layout-dependent character. This is the same matching strategy used when LanguageAgnosticKeyBindings is enabled, but applied as a last-resort fallback in the normal path. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On keyboards where the same physical key reports different
charactersIgnoringModifiersvalues depending on input method state (e.g., Chinese/Pinyin layouts where the backtick key returns 0xb7 in one mode and 0x60 in another), GlobalKeyMap key bindings become unrecognized after text input.Reproduction
The stored binding key is
0xb7-0x100000-0x32but the keystroke from the event serializes as0x60-0x100000-0x32becausecharactersIgnoringModifiersnow returns 0x60.Root Cause
In
iTermKeystroke.keyInBindingDictionary:, the normal-path fallbacks all depend on thecharacterfield (fromcharactersIgnoringModifiers):serialized—0x<char>-0x<mods>-0x<keycode>✗ (char differs)legacySerialized—0x<char>-0x<mods>✗ (char differs)modifiedSerialized—:0x<modChar>:0x<mods>✗ (char differs)None of these match when the character field varies.
Fix
Add a final fallback using
portableSerialized(*-0x<mods>-0x<keycode>), which matches on virtual key code and modifiers only — the same strategy already used whenLanguageAgnosticKeyBindingsis enabled. This is a 15-line addition that only activates when all existing matching strategies have failed, so it's fully backward-compatible.Commits
keyInBindingDictionary:matching logic, plus a Swift XCTestTesting
Run
tests/reproduce_keystroke_bug.pyto verify the fix:The Swift XCTest in
ModernTests/iTermKeystrokeBindingTests.swiftcovers the same scenarios and can be run with Xcode.🤖 Generated with Claude Code