From 553687b5e2c0e48ca6208e0bf7f4a91717837d1c Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 23 Oct 2024 20:12:58 +0200 Subject: [PATCH 1/3] feat: make too big tab indices go to last tab --- macos/Sources/Features/Terminal/TerminalController.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 0b1ff3b72..a015d88d6 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -211,7 +211,7 @@ class TerminalController: BaseTerminalController { window.restorationClass = TerminalWindowRestoration.self window.identifier = .init(String(describing: TerminalWindowRestoration.self)) } - + // If window decorations are disabled, remove our title if (!ghostty.config.windowDecorations) { window.styleMask.remove(.titled) } @@ -518,7 +518,10 @@ class TerminalController: BaseTerminalController { finalIndex = Int(tabIndex - 1) } - guard finalIndex >= 0 && finalIndex < tabbedWindows.count else { return } + guard finalIndex >= 0 else { return } + if finalIndex >= tabbedWindows.count { + finalIndex = tabbedWindows.count - 1 + } let targetWindow = tabbedWindows[finalIndex] targetWindow.makeKeyAndOrderFront(nil) } From a651dbf3bf884c5f3ba47f13ed035762da8979b2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 24 Oct 2024 19:56:52 -0700 Subject: [PATCH 2/3] macos: fix goto last tab --- .../Sources/Features/Terminal/TerminalController.swift | 10 +++++----- src/input/Binding.zig | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index a015d88d6..d06cb0d3e 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -514,14 +514,14 @@ class TerminalController: BaseTerminalController { return } } else { - // Tabs are 0-indexed here, so we subtract one from the key the user hit. - finalIndex = Int(tabIndex - 1) + // The configured value is 1-indexed. + guard tabIndex >= 1 else { return } + + // If our index is outside our boundary then we use the max + finalIndex = min(Int(tabIndex - 1), tabbedWindows.count - 1) } guard finalIndex >= 0 else { return } - if finalIndex >= tabbedWindows.count { - finalIndex = tabbedWindows.count - 1 - } let targetWindow = tabbedWindows[finalIndex] targetWindow.makeKeyAndOrderFront(nil) } diff --git a/src/input/Binding.zig b/src/input/Binding.zig index c9e90d946..64016659a 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -297,7 +297,8 @@ pub const Action = union(enum) { /// Go to the last tab (the one with the highest index) last_tab: void, - /// Go to the tab with the specific number, 1-indexed. + /// Go to the tab with the specific number, 1-indexed. If the tab number + /// is higher than the number of tabs, this will go to the last tab. goto_tab: usize, /// Toggle the tab overview. From a793ad2f0d1420108f5f512a813b2368b73024d5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 24 Oct 2024 20:01:07 -0700 Subject: [PATCH 3/3] gtk: make goto_tab go to last tab if too large --- src/apprt/gtk/Window.zig | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/apprt/gtk/Window.zig b/src/apprt/gtk/Window.zig index 65041d600..1b29cd5e2 100644 --- a/src/apprt/gtk/Window.zig +++ b/src/apprt/gtk/Window.zig @@ -466,11 +466,10 @@ pub fn gotoLastTab(self: *Window) void { pub fn gotoTab(self: *Window, n: usize) void { if (n == 0) return; const max = self.notebook.nPages(); + if (max == 0) return; const page_idx = std.math.cast(c_int, n - 1) orelse return; - if (page_idx < max) { - self.notebook.gotoNthTab(page_idx); - self.focusCurrentTab(); - } + self.notebook.gotoNthTab(@min(page_idx, max - 1)); + self.focusCurrentTab(); } /// Toggle tab overview (if present)