Improves helder

This commit is contained in:
2026-10-05 09:24:25 +02:00
parent 8fafea4fc3
commit 336987d821
44 changed files with 3454 additions and 542 deletions
+85 -9
View File
@@ -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