Improves helder
This commit is contained in:
@@ -18,13 +18,37 @@ public struct ColumnLayoutSnapshot: Codable, Sendable, Equatable {
|
||||
public var agentWidth: Double
|
||||
public var fluid: Bool
|
||||
public var gitVisible: Bool
|
||||
public var explorerVisible: Bool
|
||||
public var fileVisible: Bool
|
||||
public var claudeVisible: Bool
|
||||
|
||||
public init(sourceControlWidth: Double, explorerWidth: Double, agentWidth: Double, fluid: Bool, gitVisible: Bool) {
|
||||
public init(sourceControlWidth: Double, explorerWidth: Double, agentWidth: Double, fluid: Bool,
|
||||
visibility: ColumnVisibility = .all) {
|
||||
self.sourceControlWidth = sourceControlWidth
|
||||
self.explorerWidth = explorerWidth
|
||||
self.agentWidth = agentWidth
|
||||
self.fluid = fluid
|
||||
self.gitVisible = gitVisible
|
||||
gitVisible = visibility.sourceControl
|
||||
explorerVisible = visibility.explorer
|
||||
fileVisible = visibility.editor
|
||||
claudeVisible = visibility.agent
|
||||
}
|
||||
|
||||
/// Older snapshots only know `gitVisible`; a missing flag means shown.
|
||||
public init(from decoder: Decoder) throws {
|
||||
let c = try decoder.container(keyedBy: CodingKeys.self)
|
||||
sourceControlWidth = try c.decode(Double.self, forKey: .sourceControlWidth)
|
||||
explorerWidth = try c.decode(Double.self, forKey: .explorerWidth)
|
||||
agentWidth = try c.decode(Double.self, forKey: .agentWidth)
|
||||
fluid = try c.decode(Bool.self, forKey: .fluid)
|
||||
gitVisible = try c.decodeIfPresent(Bool.self, forKey: .gitVisible) ?? true
|
||||
explorerVisible = try c.decodeIfPresent(Bool.self, forKey: .explorerVisible) ?? true
|
||||
fileVisible = try c.decodeIfPresent(Bool.self, forKey: .fileVisible) ?? true
|
||||
claudeVisible = try c.decodeIfPresent(Bool.self, forKey: .claudeVisible) ?? true
|
||||
}
|
||||
|
||||
public var visibility: ColumnVisibility {
|
||||
ColumnVisibility(sourceControl: gitVisible, explorer: explorerVisible, editor: fileVisible, agent: claudeVisible)
|
||||
}
|
||||
|
||||
public static func key(root: String) -> String { "helder.layout:" + root }
|
||||
@@ -71,8 +95,8 @@ public final class LayoutStore {
|
||||
/// The agent pane's share of the right column; persisted across launches.
|
||||
public private(set) var agentFraction: Double
|
||||
public private(set) var windowWidth: Double = 1680
|
||||
/// ⌘G: the Source Control column is shown.
|
||||
public private(set) var gitVisible = true
|
||||
/// The title bar's pane toggles; ⌘G flips Source Control.
|
||||
public private(set) var visibility = ColumnVisibility.all
|
||||
/// ⌘L: columns re-fit on resize and focus. A manual splitter drag turns this off.
|
||||
public private(set) var fluid = true
|
||||
/// ⌘.: dotfiles show in the tree and the search.
|
||||
@@ -122,7 +146,7 @@ public final class LayoutStore {
|
||||
activePanel = nil
|
||||
focusZone = .neutral
|
||||
let saved = persistence?.load(root: root)
|
||||
gitVisible = saved?.gitVisible ?? true
|
||||
visibility = saved?.visibility ?? .all
|
||||
fluid = saved?.fluid ?? true
|
||||
if let saved, !saved.fluid {
|
||||
widths = ColumnWidths(sourceControl: clamp(saved.sourceControlWidth, ColumnLayout.sourceControlRange),
|
||||
@@ -134,12 +158,32 @@ public final class LayoutStore {
|
||||
|
||||
public var snapshot: ColumnLayoutSnapshot {
|
||||
ColumnLayoutSnapshot(sourceControlWidth: widths.sourceControl, explorerWidth: widths.explorer,
|
||||
agentWidth: widths.agent, fluid: fluid, gitVisible: gitVisible)
|
||||
agentWidth: widths.agent, fluid: fluid, visibility: visibility)
|
||||
}
|
||||
|
||||
public func toggleGit() {
|
||||
gitVisible.toggle()
|
||||
if !gitVisible && activePanel == .sourceControl { activePanel = nil }
|
||||
public func isVisible(_ panel: Panel) -> Bool {
|
||||
switch panel {
|
||||
case .sourceControl: visibility.sourceControl
|
||||
case .explorer: visibility.explorer
|
||||
case .editor: visibility.editor
|
||||
case .terminal: visibility.agent
|
||||
}
|
||||
}
|
||||
|
||||
/// Shows or hides one column; a hidden column loses keyboard focus but keeps everything inside it.
|
||||
public func togglePane(_ panel: Panel) {
|
||||
setVisible(panel, !isVisible(panel))
|
||||
}
|
||||
|
||||
public func setVisible(_ panel: Panel, _ visible: Bool) {
|
||||
guard isVisible(panel) != visible else { return }
|
||||
switch panel {
|
||||
case .sourceControl: visibility.sourceControl = visible
|
||||
case .explorer: visibility.explorer = visible
|
||||
case .editor: visibility.editor = visible
|
||||
case .terminal: visibility.agent = visible
|
||||
}
|
||||
if !visible && activePanel == panel { activePanel = nil }
|
||||
refit()
|
||||
save()
|
||||
}
|
||||
@@ -161,7 +205,7 @@ public final class LayoutStore {
|
||||
|
||||
/// Focus moves the fluid widths below 1600pt: the editor or the terminals get more room.
|
||||
public func focus(_ panel: Panel) {
|
||||
if panel == .sourceControl && !gitVisible { return }
|
||||
guard isVisible(panel) else { return }
|
||||
activePanel = panel
|
||||
switch panel {
|
||||
case .editor: focusZone = .editor
|
||||
@@ -190,7 +234,7 @@ public final class LayoutStore {
|
||||
/// The agent splitter sits on the column's left edge, so dragging right shrinks it.
|
||||
public func dragAgent(by delta: Double) {
|
||||
fluid = false
|
||||
let maxWidth = ColumnLayout.maxAgentWidth(windowWidth: windowWidth, widths: widths, sourceControlVisible: gitVisible)
|
||||
let maxWidth = ColumnLayout.maxAgentWidth(windowWidth: windowWidth, widths: widths, visible: visibility)
|
||||
widths.agent = clamp(widths.agent - delta, ColumnLayout.minEditorWidth...maxWidth)
|
||||
}
|
||||
|
||||
@@ -214,19 +258,22 @@ public final class LayoutStore {
|
||||
|
||||
/// The visible columns, left to right.
|
||||
public var columns: [Panel] {
|
||||
gitVisible ? Panel.allCases : [.explorer, .editor, .terminal]
|
||||
Panel.allCases.filter(isVisible)
|
||||
}
|
||||
|
||||
/// The horizontal extent of a column in window coordinates; nil for a hidden column.
|
||||
/// The editor is the flex column; with the editor hidden the agent column fills the rest.
|
||||
public func span(of panel: Panel) -> ClosedRange<Double>? {
|
||||
guard isVisible(panel) else { return nil }
|
||||
let splitter = ColumnLayout.splitterWidth
|
||||
let sc = gitVisible ? widths.sourceControl + splitter : 0
|
||||
let editorStart = sc + widths.explorer + splitter
|
||||
let agentStart = max(editorStart, windowWidth - widths.agent)
|
||||
let v = visibility
|
||||
let explorerStart = v.sourceControl ? widths.sourceControl + splitter : 0
|
||||
let flexStart = explorerStart + (v.explorer ? widths.explorer + splitter : 0)
|
||||
let agentStart = v.editor ? max(flexStart, windowWidth - widths.agent) : flexStart
|
||||
switch panel {
|
||||
case .sourceControl: return gitVisible ? 0...widths.sourceControl : nil
|
||||
case .explorer: return sc...(sc + widths.explorer)
|
||||
case .editor: return editorStart...max(editorStart, agentStart - splitter)
|
||||
case .sourceControl: return 0...widths.sourceControl
|
||||
case .explorer: return explorerStart...(explorerStart + widths.explorer)
|
||||
case .editor: return flexStart...max(flexStart, v.agent ? agentStart - splitter : windowWidth)
|
||||
case .terminal: return agentStart...max(agentStart, windowWidth)
|
||||
}
|
||||
}
|
||||
@@ -242,13 +289,14 @@ public final class LayoutStore {
|
||||
/// The column `step` places left (−1) or right (+1) of `panel`, clamped at the ends. No focus counts as the editor.
|
||||
public func neighbour(of panel: Panel?, step: Int) -> Panel {
|
||||
let list = columns
|
||||
guard !list.isEmpty else { return panel ?? .editor }
|
||||
let index = list.firstIndex(of: panel ?? .editor) ?? list.firstIndex(of: .editor) ?? 0
|
||||
return list[min(max(index + step, 0), list.count - 1)]
|
||||
}
|
||||
|
||||
private func refit() {
|
||||
var next = fluid ? ColumnLayout.fluid(windowWidth: windowWidth, focus: focusZone) : widths
|
||||
next = ColumnLayout.fitted(next, windowWidth: windowWidth, sourceControlVisible: gitVisible)
|
||||
next = ColumnLayout.fitted(next, windowWidth: windowWidth, visible: visibility)
|
||||
if next != widths { widths = next }
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,8 @@ public final class WorkspaceModel {
|
||||
case let .launcherSelect(index): launcher.select(index)
|
||||
case .launcherActivate: activateLauncher()
|
||||
|
||||
case .toggleGit: layout.toggleGit()
|
||||
case .toggleGit: layout.togglePane(.sourceControl)
|
||||
case let .togglePane(panel): layout.togglePane(panel)
|
||||
case .toggleAutoFit: layout.toggleFluid()
|
||||
case .toggleHidden: layout.toggleHidden()
|
||||
case let .focus(panel): focus(panel)
|
||||
@@ -180,7 +181,7 @@ public final class WorkspaceModel {
|
||||
guard let sourceControl else { return }
|
||||
track { _ = await sourceControl.push() }
|
||||
case .focusCommitMessage:
|
||||
if !layout.gitVisible { layout.toggleGit() }
|
||||
layout.setVisible(.sourceControl, true)
|
||||
layout.focus(.sourceControl)
|
||||
focusRequest = FocusRequest(.commitMessage)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user