mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
Merge pull request #2482 from max397574/push-snqtmwzyxmwx
feat: make too big tab indices go to last tab
This commit is contained in:
@ -211,7 +211,7 @@ class TerminalController: BaseTerminalController {
|
|||||||
window.restorationClass = TerminalWindowRestoration.self
|
window.restorationClass = TerminalWindowRestoration.self
|
||||||
window.identifier = .init(String(describing: TerminalWindowRestoration.self))
|
window.identifier = .init(String(describing: TerminalWindowRestoration.self))
|
||||||
}
|
}
|
||||||
|
|
||||||
// If window decorations are disabled, remove our title
|
// If window decorations are disabled, remove our title
|
||||||
if (!ghostty.config.windowDecorations) { window.styleMask.remove(.titled) }
|
if (!ghostty.config.windowDecorations) { window.styleMask.remove(.titled) }
|
||||||
|
|
||||||
@ -514,11 +514,14 @@ class TerminalController: BaseTerminalController {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Tabs are 0-indexed here, so we subtract one from the key the user hit.
|
// The configured value is 1-indexed.
|
||||||
finalIndex = Int(tabIndex - 1)
|
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 && finalIndex < tabbedWindows.count else { return }
|
guard finalIndex >= 0 else { return }
|
||||||
let targetWindow = tabbedWindows[finalIndex]
|
let targetWindow = tabbedWindows[finalIndex]
|
||||||
targetWindow.makeKeyAndOrderFront(nil)
|
targetWindow.makeKeyAndOrderFront(nil)
|
||||||
}
|
}
|
||||||
|
@ -466,11 +466,10 @@ pub fn gotoLastTab(self: *Window) void {
|
|||||||
pub fn gotoTab(self: *Window, n: usize) void {
|
pub fn gotoTab(self: *Window, n: usize) void {
|
||||||
if (n == 0) return;
|
if (n == 0) return;
|
||||||
const max = self.notebook.nPages();
|
const max = self.notebook.nPages();
|
||||||
|
if (max == 0) return;
|
||||||
const page_idx = std.math.cast(c_int, n - 1) orelse return;
|
const page_idx = std.math.cast(c_int, n - 1) orelse return;
|
||||||
if (page_idx < max) {
|
self.notebook.gotoNthTab(@min(page_idx, max - 1));
|
||||||
self.notebook.gotoNthTab(page_idx);
|
self.focusCurrentTab();
|
||||||
self.focusCurrentTab();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Toggle tab overview (if present)
|
/// Toggle tab overview (if present)
|
||||||
|
@ -297,7 +297,8 @@ pub const Action = union(enum) {
|
|||||||
/// Go to the last tab (the one with the highest index)
|
/// Go to the last tab (the one with the highest index)
|
||||||
last_tab: void,
|
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,
|
goto_tab: usize,
|
||||||
|
|
||||||
/// Toggle the tab overview.
|
/// Toggle the tab overview.
|
||||||
|
Reference in New Issue
Block a user