mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: jump to last_tab
This commit is contained in:
@ -143,6 +143,7 @@ typedef enum {
|
||||
typedef enum {
|
||||
GHOSTTY_TAB_PREVIOUS = -1,
|
||||
GHOSTTY_TAB_NEXT = -2,
|
||||
GHOSTTY_TAB_LAST = -3,
|
||||
} ghostty_tab_e;
|
||||
|
||||
typedef enum {
|
||||
|
@ -724,6 +724,8 @@ class TerminalController: NSWindowController, NSWindowDelegate,
|
||||
} else {
|
||||
finalIndex = selectedIndex + 1
|
||||
}
|
||||
} else if (tabIndex == GHOSTTY_TAB_LAST.rawValue) {
|
||||
finalIndex = tabbedWindows.count - 1
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
@ -379,6 +379,14 @@ extension Ghostty {
|
||||
)
|
||||
}
|
||||
|
||||
static func gotoLastTab(_ userdata: UnsafeMutableRawPointer?) {
|
||||
let surface = self.surfaceUserdata(from: userdata)
|
||||
NotificationCenter.default.post(
|
||||
name: Notification.ghosttyGotoTab,
|
||||
object: surface
|
||||
)
|
||||
}
|
||||
|
||||
static func readClipboard(_ userdata: UnsafeMutableRawPointer?, location: ghostty_clipboard_e, state: UnsafeMutableRawPointer?) {
|
||||
// If we don't even have a surface, something went terrible wrong so we have
|
||||
// to leak "state".
|
||||
|
@ -3429,6 +3429,19 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
|
||||
} else log.warn("runtime doesn't implement gotoNextTab", .{});
|
||||
},
|
||||
|
||||
.last_tab => {
|
||||
if (@hasDecl(apprt.Surface, "hasTabs")) {
|
||||
if (!self.rt_surface.hasTabs()) {
|
||||
log.debug("surface has no tabs, ignoring last_tab binding", .{});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (@hasDecl(apprt.Surface, "gotoLastTab")) {
|
||||
self.rt_surface.gotoLastTab();
|
||||
} else log.warn("runtime doesn't implement gotoLastTab", .{});
|
||||
},
|
||||
|
||||
.goto_tab => |n| {
|
||||
if (@hasDecl(apprt.Surface, "gotoTab")) {
|
||||
self.rt_surface.gotoTab(n);
|
||||
|
@ -139,6 +139,7 @@ pub const App = struct {
|
||||
const GotoTab = enum(i32) {
|
||||
previous = -1,
|
||||
next = -2,
|
||||
last = -3,
|
||||
_,
|
||||
};
|
||||
|
||||
@ -1008,6 +1009,15 @@ pub const Surface = struct {
|
||||
func(self.userdata, @enumFromInt(idx));
|
||||
}
|
||||
|
||||
pub fn gotoLastTab(self: *Surface) void {
|
||||
const func = self.app.opts.goto_tab orelse {
|
||||
log.info("runtime embedder does not goto_tab", .{});
|
||||
return;
|
||||
};
|
||||
|
||||
func(self.userdata, .last);
|
||||
}
|
||||
|
||||
pub fn gotoPreviousTab(self: *Surface) void {
|
||||
const func = self.app.opts.goto_tab orelse {
|
||||
log.info("runtime embedder does not goto_tab", .{});
|
||||
|
@ -1582,6 +1582,11 @@ pub fn default(alloc_gpa: Allocator) Allocator.Error!Config {
|
||||
.{ .key = .{ .translated = .right }, .mods = .{ .ctrl = true, .shift = true } },
|
||||
.{ .next_tab = {} },
|
||||
);
|
||||
try result.keybind.set.put(
|
||||
alloc,
|
||||
.{ .key = .{ .physical = inputpkg.Key.zero }, .mods = .{ .super = true } },
|
||||
.{ .last_tab = {} },
|
||||
);
|
||||
try result.keybind.set.put(
|
||||
alloc,
|
||||
.{ .key = .{ .translated = .page_up }, .mods = .{ .ctrl = true } },
|
||||
@ -1850,6 +1855,11 @@ pub fn default(alloc_gpa: Allocator) Allocator.Error!Config {
|
||||
.{ .key = .{ .translated = .right_bracket }, .mods = .{ .super = true, .shift = true } },
|
||||
.{ .next_tab = {} },
|
||||
);
|
||||
try result.keybind.set.put(
|
||||
alloc,
|
||||
.{ .key = .{ .physical = inputpkg.Key.zero }, .mods = .{ .super = true } },
|
||||
.{ .last_tab = {} },
|
||||
);
|
||||
try result.keybind.set.put(
|
||||
alloc,
|
||||
.{ .key = .{ .translated = .d }, .mods = .{ .super = true } },
|
||||
|
@ -257,6 +257,9 @@ pub const Action = union(enum) {
|
||||
/// Go to the next tab.
|
||||
next_tab: void,
|
||||
|
||||
/// Go to the last tab (the one with the highest index)
|
||||
last_tab: void,
|
||||
|
||||
/// Go to the tab with the specific number, 1-indexed.
|
||||
goto_tab: usize,
|
||||
|
||||
|
Reference in New Issue
Block a user