From ff3d0eb8b7084d3788334dcc67ca3cf59316eba3 Mon Sep 17 00:00:00 2001 From: Momo Date: Sun, 24 May 2026 21:20:04 -0700 Subject: [PATCH] =?UTF-8?q?feat(macos):=20add=20SurfaceTitleBar=20?= =?UTF-8?q?=E2=80=94=20inline-editable=20split=20pane=20title=20strip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Surface View/SurfaceTitleBar.swift | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 macos/Sources/Ghostty/Surface View/SurfaceTitleBar.swift diff --git a/macos/Sources/Ghostty/Surface View/SurfaceTitleBar.swift b/macos/Sources/Ghostty/Surface View/SurfaceTitleBar.swift new file mode 100644 index 000000000..01f6b1afa --- /dev/null +++ b/macos/Sources/Ghostty/Surface View/SurfaceTitleBar.swift @@ -0,0 +1,63 @@ +import SwiftUI + +#if canImport(AppKit) + +struct SurfaceTitleBar: View { + @ObservedObject var surfaceView: Ghostty.SurfaceView + + @State private var isEditing = false + @State private var editText = "" + @FocusState private var fieldFocused: Bool + + private var displayTitle: String { + if surfaceView.isUserSetTitle { + return surfaceView.title + } + return URL(fileURLWithPath: surfaceView.pwd ?? "/").lastPathComponent + } + + var body: some View { + ZStack { + Rectangle() + .fill(.ultraThinMaterial) + + if isEditing { + TextField("", text: $editText) + .textFieldStyle(.plain) + .multilineTextAlignment(.center) + .focused($fieldFocused) + .onSubmit { commit() } + .onExitCommand { cancel() } + .onChange(of: fieldFocused) { focused in + if !focused { commit() } + } + .padding(.horizontal, 8) + } else { + Text(displayTitle) + .lineLimit(1) + .truncationMode(.middle) + .foregroundStyle(.secondary) + .onTapGesture(count: 2) { startEditing() } + } + } + .frame(height: 22) + .frame(maxWidth: .infinity) + } + + private func startEditing() { + editText = surfaceView.isUserSetTitle ? surfaceView.title : "" + isEditing = true + fieldFocused = true + } + + private func commit() { + surfaceView.setPinnedTitle(editText.isEmpty ? nil : editText) + isEditing = false + } + + private func cancel() { + isEditing = false + } +} + +#endif