Improves helder
This commit is contained in:
@@ -74,8 +74,10 @@ public enum Command: Equatable, Sendable {
|
||||
|
||||
// MARK: Layout and focus
|
||||
|
||||
/// ⌘G
|
||||
/// ⌘G: the Source Control pane toggle.
|
||||
case toggleGit
|
||||
/// A title-bar pane toggle: shows or hides one column.
|
||||
case togglePane(Panel)
|
||||
/// ⌘L
|
||||
case toggleAutoFit
|
||||
/// ⌘.
|
||||
|
||||
@@ -66,10 +66,19 @@ struct HelderCommands: Commands {
|
||||
.keyboardShortcut("r", modifiers: .command)
|
||||
.disabled(workspace?.root == nil)
|
||||
Divider()
|
||||
Button(workspace?.layout.gitVisible == false ? "Show Source Control" : "Hide Source Control") {
|
||||
Button(workspace?.layout.isVisible(.sourceControl) == false ? "Show Source Control" : "Hide Source Control") {
|
||||
workspace?.perform(.toggleGit)
|
||||
}
|
||||
.keyboardShortcut("g", modifiers: .command)
|
||||
Button(workspace?.layout.isVisible(.explorer) == false ? "Show Explorer" : "Hide Explorer") {
|
||||
workspace?.perform(.togglePane(.explorer))
|
||||
}
|
||||
Button(workspace?.layout.isVisible(.editor) == false ? "Show File" : "Hide File") {
|
||||
workspace?.perform(.togglePane(.editor))
|
||||
}
|
||||
Button(workspace?.layout.isVisible(.terminal) == false ? "Show Claude" : "Hide Claude") {
|
||||
workspace?.perform(.togglePane(.terminal))
|
||||
}
|
||||
Button(workspace?.layout.fluid == false ? "Fluid Column Widths" : "Lock Column Widths") {
|
||||
workspace?.perform(.toggleAutoFit)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import HelderCore
|
||||
import SwiftUI
|
||||
|
||||
/// 44pt bar: traffic-light inset, wordmark, project · branch, the open file's breadcrumb, and the toolbar.
|
||||
/// 44pt bar: traffic-light inset, wordmark, project · branch, the open file's breadcrumb, the pane toggles
|
||||
/// centred on the window, and the toolbar.
|
||||
struct TitleBarView: View {
|
||||
let model: WorkspaceModel
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: Metrics.titleBarGap) {
|
||||
TitleBarLayout(leading: model.layout.isFullScreen ? 14 : Metrics.trafficLightInset, trailing: 14, gap: Metrics.titleBarGap) {
|
||||
HStack(alignment: .firstTextBaseline, spacing: Metrics.titleClusterGap) {
|
||||
Wordmark()
|
||||
ProjectName(name: model.name) { model.perform(.openFolder) }
|
||||
@@ -19,16 +20,45 @@ struct TitleBarView: View {
|
||||
.fixedSize()
|
||||
Breadcrumb(path: model.editor?.activePath, isDirty: model.editor.map { e in e.activePath.map(e.isDirty) ?? false } ?? false)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
PaneToggles(model: model)
|
||||
TitleToolbar(model: model)
|
||||
}
|
||||
.padding(.leading, model.layout.isFullScreen ? 14 : Metrics.trafficLightInset)
|
||||
.padding(.trailing, 14)
|
||||
.frame(height: Metrics.titleBar)
|
||||
.background(Palette.panel)
|
||||
.hairline(.bottom)
|
||||
}
|
||||
}
|
||||
|
||||
/// Lays out the four title-bar parts: the pane toggles sit on the window's centre, and the breadcrumb
|
||||
/// gets only the room left of them. The toggles move left only when the toolbar would run into them.
|
||||
private struct TitleBarLayout: Layout {
|
||||
var leading: CGFloat
|
||||
var trailing: CGFloat
|
||||
var gap: CGFloat
|
||||
|
||||
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
|
||||
CGSize(width: proposal.width ?? 0, height: proposal.height ?? Metrics.titleBar)
|
||||
}
|
||||
|
||||
func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
|
||||
guard subviews.count == 4 else { return }
|
||||
let (cluster, crumb, toggles, toolbar) = (subviews[0], subviews[1], subviews[2], subviews[3])
|
||||
let y = bounds.midY
|
||||
let clusterSize = cluster.sizeThatFits(.unspecified)
|
||||
let togglesSize = toggles.sizeThatFits(.unspecified)
|
||||
let toolbarSize = toolbar.sizeThatFits(.unspecified)
|
||||
let clusterX = bounds.minX + leading
|
||||
let toolbarX = bounds.maxX - trailing - toolbarSize.width
|
||||
let togglesX = min(bounds.midX - togglesSize.width / 2, toolbarX - gap - togglesSize.width)
|
||||
let crumbX = clusterX + clusterSize.width + gap
|
||||
cluster.place(at: CGPoint(x: clusterX, y: y), anchor: .leading, proposal: ProposedViewSize(clusterSize))
|
||||
toggles.place(at: CGPoint(x: togglesX, y: y), anchor: .leading, proposal: ProposedViewSize(togglesSize))
|
||||
toolbar.place(at: CGPoint(x: toolbarX, y: y), anchor: .leading, proposal: ProposedViewSize(toolbarSize))
|
||||
crumb.place(at: CGPoint(x: crumbX, y: y), anchor: .leading,
|
||||
proposal: ProposedViewSize(width: max(0, togglesX - gap - crumbX), height: bounds.height))
|
||||
}
|
||||
}
|
||||
|
||||
private struct ProjectName: View {
|
||||
let name: String
|
||||
let action: () -> Void
|
||||
@@ -58,7 +88,7 @@ private struct Breadcrumb: View {
|
||||
ForEach(Array(segments.enumerated()), id: \.offset) { index, segment in
|
||||
if index > 0 { Text("›").foregroundStyle(Palette.text4) }
|
||||
if index == segments.count - 1 {
|
||||
Text(segment).typeRole(Typography.crumbLeaf).foregroundStyle(Palette.text1)
|
||||
Text(segment).typeRole(Typography.crumbLeaf).foregroundStyle(Palette.text1).layoutPriority(1)
|
||||
} else {
|
||||
Text(segment).foregroundStyle(Palette.text4)
|
||||
}
|
||||
@@ -76,42 +106,58 @@ private struct Breadcrumb: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// Search ⌘F · Fluid ⌘L · Hidden ⌘. · Note ⌘N · Git ⌘G · `?`, each with a tooltip that names its state.
|
||||
/// Git · Explorer · File · Claude: one toggle per column. Hiding a column keeps everything inside it.
|
||||
private struct PaneToggles: View {
|
||||
let model: WorkspaceModel
|
||||
|
||||
var body: some View {
|
||||
ButtonGroup([
|
||||
toggle("Git", .sourceControl, column: "Source Control"),
|
||||
toggle("Explorer", .explorer, column: "Explorer"),
|
||||
toggle("File", .editor, column: "File"),
|
||||
toggle("Claude", .terminal, column: "Claude"),
|
||||
])
|
||||
}
|
||||
|
||||
private func toggle(_ label: String, _ panel: Panel, column: String) -> GroupItem {
|
||||
let shown = model.layout.isVisible(panel)
|
||||
let tip = shown
|
||||
? Tooltip.stated(column + " column: ", "shown", ". Click to hide it.")
|
||||
: Tooltip.stated(column + " column: ", "hidden", ". Click to show it.")
|
||||
return GroupItem(label, kind: .toggle(isOn: shown), tip: tip) {
|
||||
model.perform(.togglePane(panel))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Search ⌘F · Fluid ⌘L · Hidden ⌘. · Note ⌘N, then `?`. Search and Note are actions; Fluid and Hidden toggle.
|
||||
private struct TitleToolbar: View {
|
||||
let model: WorkspaceModel
|
||||
|
||||
var body: some View {
|
||||
let layout = model.layout
|
||||
let overlay = model.overlay.current
|
||||
HStack(spacing: Metrics.toolbarGap) {
|
||||
ToolbarToggle("Search", keys: "⌘F", isOn: isSearch(overlay)) { model.perform(.showSearch(seed: "")) }
|
||||
.tip("Search the open file, the project and the file names.", edge: .trailing)
|
||||
ToolbarToggle("Fluid", keys: "⌘L", isOn: layout.fluid) { model.perform(.toggleAutoFit) }
|
||||
.tip(layout.fluid
|
||||
? Tooltip.stated("Column widths: ", "fluid", " — the columns re-fit on resize and focus. Click to lock them.")
|
||||
: Tooltip.stated("Column widths: ", "locked", " — the columns keep their size. Click to make them fluid."),
|
||||
edge: .trailing)
|
||||
ToolbarToggle("Hidden", keys: "⌘.", isOn: layout.showHidden, muted: !layout.showHidden) { model.perform(.toggleHidden) }
|
||||
.tip(layout.showHidden
|
||||
? Tooltip.stated("Hidden files: ", "shown", " — dotfiles appear in the tree and the search. Click to hide them.")
|
||||
: Tooltip.stated("Hidden files: ", "hidden", " — dotfiles are excluded from the tree and the search. Click to show them."),
|
||||
edge: .trailing)
|
||||
ToolbarToggle("Note", keys: "⌘N", isOn: overlay == .note) { model.perform(.showNote) }
|
||||
.tip("Project note (.notes.txt) — kept next to this project.", edge: .trailing)
|
||||
ToolbarToggle("Git", keys: "⌘G", isOn: layout.gitVisible) { model.perform(.toggleGit) }
|
||||
.tip(layout.gitVisible
|
||||
? Tooltip.stated("Source Control column: ", "shown", ". Click to hide it.")
|
||||
: Tooltip.stated("Source Control column: ", "hidden", ". Click to show it."),
|
||||
edge: .trailing)
|
||||
HStack(spacing: Metrics.toolbarIconGap) {
|
||||
ButtonGroup([
|
||||
GroupItem("Search", keys: "⌘F", kind: .action,
|
||||
tip: Text("Search the open file, the project and the file names.")) { model.perform(.showSearch(seed: "")) },
|
||||
GroupItem("Fluid", keys: "⌘L", kind: .toggle(isOn: layout.fluid),
|
||||
tip: layout.fluid
|
||||
? Tooltip.stated("Column widths: ", "fluid", " — the columns re-fit on resize and focus. Click to lock them.")
|
||||
: Tooltip.stated("Column widths: ", "locked", " — the columns keep their size. Click to make them fluid.")) {
|
||||
model.perform(.toggleAutoFit)
|
||||
},
|
||||
GroupItem("Hidden", keys: "⌘.", kind: .toggle(isOn: layout.showHidden),
|
||||
tip: layout.showHidden
|
||||
? Tooltip.stated("Hidden files: ", "shown", " — dotfiles appear in the tree and the search. Click to hide them.")
|
||||
: Tooltip.stated("Hidden files: ", "hidden", " — dotfiles are excluded from the tree and the search. Click to show them.")) {
|
||||
model.perform(.toggleHidden)
|
||||
},
|
||||
GroupItem("Note", keys: "⌘N", kind: .action,
|
||||
tip: Text("Project note (.notes.txt) — kept next to this project.")) { model.perform(.showNote) },
|
||||
], tipEdge: .trailing)
|
||||
ToolbarIconButton("?") { model.perform(.showShortcuts) }
|
||||
.padding(.leading, 6)
|
||||
.tip("Keyboard shortcuts.", edge: .trailing)
|
||||
}
|
||||
.fixedSize()
|
||||
}
|
||||
|
||||
private func isSearch(_ overlay: Overlay) -> Bool {
|
||||
if case .search = overlay { return true }
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import AppKit
|
||||
import HelderCore
|
||||
import SwiftUI
|
||||
|
||||
/// The launcher without a project; with one, the title bar, four columns and status bar, overlays above.
|
||||
@@ -37,35 +39,109 @@ struct WorkspaceView: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// The four columns and their splitters. The agent column is keyed by the project so its terminals respawn on a switch.
|
||||
/// The four columns and their splitters. Every column stays mounted: a pane toggle only hides it, so the
|
||||
/// terminals, the editor buffer and the tree keep their state. The editor is the flex column; with the editor
|
||||
/// hidden the agent column fills. The agent column is keyed by the project so its terminals respawn on a switch.
|
||||
private struct Columns: View {
|
||||
let model: WorkspaceModel
|
||||
/// The editor's last shown width, kept while it is hidden so its text does not re-wrap.
|
||||
@State private var editorWidth = Metrics.minEditorWidth
|
||||
|
||||
var body: some View {
|
||||
let layout = model.layout
|
||||
let v = layout.visibility
|
||||
let agentFills = v.agent && !v.editor
|
||||
let hiddenEditorWidth = max(editorWidth, Metrics.minEditorWidth)
|
||||
HStack(spacing: 0) {
|
||||
if layout.gitVisible {
|
||||
SourceControlColumn(model: model)
|
||||
.frame(width: layout.widths.sourceControl)
|
||||
.refreshFlash(model.refreshTick)
|
||||
Splitter(onDrag: { layout.dragSourceControl(by: $0) }, onEnd: layout.endDrag)
|
||||
}
|
||||
SourceControlColumn(model: model)
|
||||
.frame(width: layout.widths.sourceControl)
|
||||
.refreshFlash(model.refreshTick)
|
||||
.pane(shown: v.sourceControl)
|
||||
Splitter(onDrag: { layout.dragSourceControl(by: $0) }, onEnd: layout.endDrag)
|
||||
.pane(shown: v.sourceControl && (v.explorer || v.editor || v.agent))
|
||||
ExplorerColumn(model: model)
|
||||
.frame(width: layout.widths.explorer)
|
||||
.refreshFlash(model.refreshTick)
|
||||
.pane(shown: v.explorer)
|
||||
Splitter(onDrag: { layout.dragExplorer(by: $0) }, onEnd: layout.endDrag)
|
||||
.pane(shown: v.explorer && (v.editor || v.agent))
|
||||
EditorColumn(model: model)
|
||||
.frame(minWidth: Metrics.minEditorWidth, maxWidth: .infinity)
|
||||
.frame(minWidth: v.editor ? Metrics.minEditorWidth : hiddenEditorWidth, maxWidth: v.editor ? .infinity : hiddenEditorWidth)
|
||||
.onGeometryChange(for: CGFloat.self) { $0.size.width } action: { width in
|
||||
if v.editor { editorWidth = width }
|
||||
}
|
||||
.refreshFlash(model.refreshTick)
|
||||
.pane(shown: v.editor)
|
||||
Splitter(onDrag: { layout.dragAgent(by: $0) }, onEnd: layout.endDrag)
|
||||
.pane(shown: v.editor && v.agent)
|
||||
AgentColumn(model: model)
|
||||
.frame(width: layout.widths.agent)
|
||||
.frame(minWidth: agentFills ? Metrics.minEditorWidth : layout.widths.agent,
|
||||
maxWidth: agentFills ? .infinity : layout.widths.agent)
|
||||
.id(model.root)
|
||||
.pane(shown: v.agent)
|
||||
if !v.editor && !v.agent {
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
}
|
||||
.background(Palette.editor)
|
||||
.background(HiddenPaneFocusGuard(visibility: v))
|
||||
.clipped()
|
||||
}
|
||||
}
|
||||
|
||||
/// Hides a column without unmounting it. The hidden column keeps its own width, so a terminal never
|
||||
/// resizes to nothing, and is parked outside the window, so its AppKit views own no pixels, clicks or cursor.
|
||||
private struct PaneVisibility: ViewModifier {
|
||||
static let parkedOffset: CGFloat = 100_000
|
||||
let shown: Bool
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.frame(width: shown ? nil : 0, alignment: .leading)
|
||||
.opacity(shown ? 1 : 0)
|
||||
.allowsHitTesting(shown)
|
||||
.accessibilityHidden(!shown)
|
||||
.offset(x: shown ? 0 : Self.parkedOffset)
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
fileprivate func pane(shown: Bool) -> some View {
|
||||
modifier(PaneVisibility(shown: shown))
|
||||
}
|
||||
}
|
||||
|
||||
/// When a column is hidden while it holds the keyboard (a terminal, the code, the commit box), the window
|
||||
/// takes the keyboard back, so typing never lands in a pane nobody can see.
|
||||
private struct HiddenPaneFocusGuard: NSViewRepresentable {
|
||||
let visibility: ColumnVisibility
|
||||
|
||||
func makeNSView(context: Context) -> GuardView {
|
||||
GuardView()
|
||||
}
|
||||
|
||||
func updateNSView(_ view: GuardView, context: Context) {
|
||||
view.visibility = visibility
|
||||
}
|
||||
|
||||
final class GuardView: NSView {
|
||||
var visibility: ColumnVisibility? {
|
||||
didSet {
|
||||
guard let oldValue, oldValue != visibility else { return }
|
||||
DispatchQueue.main.async { [weak self] in self?.releaseParkedResponder() }
|
||||
}
|
||||
}
|
||||
|
||||
override func hitTest(_ point: NSPoint) -> NSView? { nil }
|
||||
|
||||
private func releaseParkedResponder() {
|
||||
guard let window, let responder = window.firstResponder as? NSView, let content = window.contentView else { return }
|
||||
let view = responder.enclosingScrollView ?? responder
|
||||
if view.convert(view.bounds, to: nil).minX >= content.bounds.maxX { window.makeFirstResponder(nil) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// ⌘R lightens a column for a moment and lets it settle back; each new tick replays it.
|
||||
private struct RefreshFlash: ViewModifier {
|
||||
let tick: Int
|
||||
|
||||
Reference in New Issue
Block a user