macos: new tab implementation

This commit is contained in:
Mitchell Hashimoto
2023-02-19 09:04:51 -08:00
parent 94e678ed57
commit e92d90b8d5
3 changed files with 17 additions and 0 deletions

View File

@ -23,6 +23,20 @@ struct GhosttyApp: App {
TerminalView(app: ghostty.app!)
.modifier(WindowObservationModifier())
}
}.commands {
CommandGroup(after: .newItem) {
Button("New Tab", action: newTab).keyboardShortcut("t", modifiers: [.command])
}
}
}
// Create a new tab in the currently active window
func newTab() {
guard let currentWindow = NSApp.keyWindow else { return }
guard let windowController = currentWindow.windowController else { return }
windowController.newWindowForTab(nil)
if let newWindow = NSApp.keyWindow, currentWindow != newWindow {
currentWindow.addTabbedWindow(newWindow, ordered: .above)
}
}
}

View File

@ -5,6 +5,7 @@ struct TerminalView: View {
let app: ghostty_app_t
@FocusState private var surfaceFocus: Bool
@Environment(\.isKeyWindow) private var isKeyWindow: Bool
@Environment(\.openWindow) private var openWindow
@State private var title: String = "Ghostty"
// This is true if the terminal is considered "focused". The terminal is focused if

View File

@ -219,6 +219,8 @@ fn newTab(self: *App, msg: Message.NewWindow) !void {
return;
}
// In embedded mode, it is up to the embedder to implement tabbing
// on their own.
if (comptime build_config.artifact != .exe) {
log.warn("tabbing is not supported in embedded mode", .{});
return;