config: bind both physical digit plus unicode digit for goto_tab

Fixes #8478

The comments explain this.
This commit is contained in:
Mitchell Hashimoto
2025-09-02 08:48:20 -07:00
parent 5ef6412823
commit 650028fa9f
3 changed files with 31 additions and 7 deletions

View File

@@ -439,8 +439,7 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
continue
}
let action = "goto_tab:\(tab)"
if let equiv = ghostty.config.keyboardShortcut(for: action) {
if let equiv = ghostty.config.keyboardShortcut(for: "goto_tab:\(tab)") {
window.keyEquivalent = "\(equiv)"
} else {
window.keyEquivalent = ""

View File

@@ -1264,7 +1264,7 @@ extension Ghostty {
var key_ev = event.ghosttyKeyEvent(action, translationMods: translationEvent?.modifierFlags)
key_ev.composing = composing
// For text, we only encode UTF8 if we don't have a single control
// character. Control characters are encoded by Ghostty itself.
// Without this, `ctrl+enter` does the wrong thing.

View File

@@ -5785,15 +5785,24 @@ pub const Keybinds = struct {
else
.{ .alt = true };
// Cmd+N for goto tab N
// Cmd/Alt+N for goto tab N
const start: u21 = '1';
const end: u21 = '8';
var i: u21 = start;
while (i <= end) : (i += 1) {
comptime var i: u21 = start;
inline while (i <= end) : (i += 1) {
// We register BOTH the physical `digit_N` key and the unicode
// `N` key. This allows most keyboard layouts to work with
// this shortcut. Namely, AZERTY doesn't produce unicode `N`
// for their digit keys (they're on shifted keys on the same
// physical keys).
try self.set.putFlags(
alloc,
.{
.key = .{ .unicode = i },
.key = .{ .physical = @field(
inputpkg.Key,
std.fmt.comptimePrint("digit_{u}", .{i}),
) },
.mods = mods,
},
.{ .goto_tab = (i - start) + 1 },
@@ -5806,6 +5815,22 @@ pub const Keybinds = struct {
.performable = !builtin.target.os.tag.isDarwin(),
},
);
// Important: this must be the LAST binding set so that the
// libghostty trigger API returns this one for the action,
// so that things like the macOS tab bar key equivalent label
// work properly.
try self.set.putFlags(
alloc,
.{
.key = .{ .unicode = i },
.mods = mods,
},
.{ .goto_tab = (i - start) + 1 },
.{
.performable = !builtin.target.os.tag.isDarwin(),
},
);
}
try self.set.putFlags(
alloc,