adds nice git interface

This commit is contained in:
2026-10-30 13:21:45 +01:00
parent b9c03a7637
commit caec81e762
107 changed files with 6466 additions and 3992 deletions
+16 -7
View File
@@ -6,7 +6,7 @@ import HelderCore
/// first responder when it names them.
public enum FocusTarget: Equatable, Sendable {
case panel(Panel)
/// ⌘C without a selection, outside a terminal: the commit message field.
/// The Git view's commit message field; ⌘G and ⌘C without a selection ask for it.
case commitMessage
}
@@ -72,9 +72,11 @@ public enum Command: Equatable, Sendable {
// MARK: Layout and focus
/// ⌘G: the Source Control pane toggle.
/// ⌘G and the title bar's Git button: opens or closes the full-screen Git view.
case toggleGit
/// A title-bar pane toggle: shows or hides one column.
/// Esc with the Git view open and no overlay over it.
case closeGitView
/// ⌘1–⌘3 and the title-bar pane toggles: shows or hides one column.
case togglePane(Panel)
/// ⌘L
case toggleAutoFit
@@ -85,11 +87,11 @@ public enum Command: Equatable, Sendable {
/// ⌘←/⌘→ outside a text field.
case focusNeighbour(step: Int)
// MARK: Row cursor in Source Control and Explorer
// MARK: Row cursor in the Explorer
/// ↑/↓
case moveRowCursor(Int)
/// ↵: git row opens its half, a file opens, a folder toggles.
/// ↵: a file opens, a folder toggles.
case openSelectedRow
/// ⌘→ on a row: its context menu, anchored to the column's right edge.
case openRowMenu
@@ -110,11 +112,18 @@ public enum Command: Equatable, Sendable {
// MARK: Git
/// ⌘↵
/// ⌘↵ and the Commit button: always runs git, so its refusal shows in the console.
case commit
/// ⌘P
case push
/// ⌘C without a selection, outside a terminal
case pull
case stage([String])
case unstage([String])
/// A branch row in the Git view; a remote one switches by its local name.
case switchBranch(String, remote: Bool)
/// ↵ in the Git console.
case submitConsoleInput
/// ⌘C without a selection, outside a terminal: opens the Git view on its message field.
case focusCommitMessage
// MARK: Clean copy
+5 -2
View File
@@ -19,7 +19,7 @@ public struct HelderScene: Scene {
}
}
/// The menu bar. Shortcuts the key router owns (⌘F, ⌘G, ⌘L, ⌘.) are shown here too; the router
/// The menu bar. Shortcuts the key router owns (⌘F, ⌘G, ⌘1–⌘3, ⌘L, ⌘.) are shown here too; the router
/// consumes them first, so the menu item fires only when a field or an overlay let the key through.
struct HelderCommands: Commands {
@FocusedValue(\.workspace) private var workspace
@@ -66,19 +66,22 @@ struct HelderCommands: Commands {
.keyboardShortcut("r", modifiers: .command)
.disabled(workspace?.root == nil)
Divider()
Button(workspace?.layout.isVisible(.sourceControl) == false ? "Show Source Control" : "Hide Source Control") {
Button(workspace?.layout.isGitViewOpen == true ? "Hide Git" : "Show Git") {
workspace?.perform(.toggleGit)
}
.keyboardShortcut("g", modifiers: .command)
Button(workspace?.layout.isVisible(.explorer) == false ? "Show Explorer" : "Hide Explorer") {
workspace?.perform(.togglePane(.explorer))
}
.keyboardShortcut("1", modifiers: .command)
Button(workspace?.layout.isVisible(.editor) == false ? "Show File" : "Hide File") {
workspace?.perform(.togglePane(.editor))
}
.keyboardShortcut("2", modifiers: .command)
Button(workspace?.layout.isVisible(.terminal) == false ? "Show Claude" : "Hide Claude") {
workspace?.perform(.togglePane(.terminal))
}
.keyboardShortcut("3", modifiers: .command)
Button(workspace?.layout.fluid == false ? "Fluid Column Widths" : "Lock Column Widths") {
workspace?.perform(.toggleAutoFit)
}
+32 -8
View File
@@ -55,11 +55,15 @@ public struct KeyContext: Equatable, Sendable {
public var recentFileCount: Int
/// The seed ⌘F uses: the first line of the current selection.
public var searchSeed: String
/// The full-screen Git view covers the columns, so their list and focus keys rest.
public var gitViewOpen: Bool
/// The keyboard sits in the Git view's console input, where ⌘↵ must not commit.
public var inGitConsole: Bool
public init(hasProject: Bool = true, overlay: OverlayKind = .none, owner: KeyboardOwner = .workspace,
hasTextSelection: Bool = false, editorTextSelection: TextSelectionInfo? = nil,
hasEditorLineSelection: Bool = false, activePanel: Panel? = nil, focusZone: FocusZone = .neutral,
recentFileCount: Int = 0, searchSeed: String = "") {
recentFileCount: Int = 0, searchSeed: String = "", gitViewOpen: Bool = false, inGitConsole: Bool = false) {
self.hasProject = hasProject
self.overlay = overlay
self.owner = owner
@@ -70,6 +74,8 @@ public struct KeyContext: Equatable, Sendable {
self.focusZone = focusZone
self.recentFileCount = recentFileCount
self.searchSeed = searchSeed
self.gitViewOpen = gitViewOpen
self.inGitConsole = inGitConsole
}
}
@@ -99,6 +105,7 @@ public enum KeyRoute: Equatable {
/// Maps a key press to a command. A key that a focused field or terminal needs is never taken:
/// arrows, ↵, `?`, ⌘A and ⌘C/⌘←/⌘→ go to the field; ⌘O, ⌘R and ⇧⌘N are left to the menu bar.
/// Esc closes the topmost layer: an overlay, then the Git view, else it reaches the terminal.
public enum KeyRouter {
public static func route(_ press: KeyPress, _ context: KeyContext) -> KeyRoute {
if press.control || press.option { return .pass }
@@ -107,7 +114,10 @@ public enum KeyRouter {
switch context.overlay {
case .diff(busy: true): return .pass
case .none: if press.key == .escape { return .pass }
case .none:
if press.key == .escape {
return context.gitViewOpen && !press.command ? .perform(.closeGitView) : .pass
}
default: if press.key == .escape && !press.command { return .perform(.dismissOverlay) }
}
switch context.overlay {
@@ -117,9 +127,24 @@ public enum KeyRouter {
case .other: return .pass
}
if context.gitViewOpen { return gitViewKey(press, context) }
return press.command ? commandKey(press, context) : plainKey(press, context)
}
/// Over the Git view the columns' row, focus and editor keys rest; ⌘↵ commits, even from the message field.
private static func gitViewKey(_ press: KeyPress, _ context: KeyContext) -> KeyRoute {
guard press.command else {
return press.key == .character("?") && context.owner == .workspace ? .perform(.showShortcuts) : .pass
}
if press.shift { return commandKey(press, context) }
switch press.key {
case .enter: return context.inGitConsole ? .pass : .perform(.commit)
case .character("a"): return .pass
case let .character(c): return commandCharacter(c, context)
default: return .pass
}
}
private static func launcherKey(_ press: KeyPress) -> KeyRoute {
guard !press.shift else { return .pass }
switch press.key {
@@ -131,7 +156,7 @@ public enum KeyRouter {
}
private static func plainKey(_ press: KeyPress, _ context: KeyContext) -> KeyRoute {
let inList = context.owner == .workspace && (context.activePanel == .sourceControl || context.activePanel == .explorer)
let inList = context.owner == .workspace && context.activePanel == .explorer
switch press.key {
case .up where inList && !press.shift: return .perform(.moveRowCursor(-1))
case .down where inList && !press.shift: return .perform(.moveRowCursor(1))
@@ -152,16 +177,12 @@ public enum KeyRouter {
return .perform(.showRecentFiles(initialSelection: ListCursor.recentFilesStart(movingDown: press.key == .down,
count: context.recentFileCount)))
case .right:
if owner == .workspace, context.activePanel == .sourceControl || context.activePanel == .explorer {
return .perform(.openRowMenu)
}
if owner == .workspace, context.activePanel == .explorer { return .perform(.openRowMenu) }
if let selection = context.editorTextSelection { return .perform(.passSelection(selection)) }
if context.hasEditorLineSelection && owner != .terminal { return .perform(.passSelection(nil)) }
return owner == .workspace ? .perform(.focusNeighbour(step: 1)) : .pass
case .left:
return owner == .workspace ? .perform(.focusNeighbour(step: -1)) : .pass
case .enter:
return owner == .text(in: .sourceControl) ? .pass : .perform(.commit)
case let .character(c):
return commandCharacter(c, context)
default:
@@ -177,6 +198,9 @@ public enum KeyRouter {
case "m": return .perform(.cycleMode)
case "w": return .perform(.closeFileOrWindow)
case "g": return .perform(.toggleGit)
case "1": return .perform(.togglePane(.explorer))
case "2": return .perform(.togglePane(.editor))
case "3": return .perform(.togglePane(.terminal))
case "l": return .perform(.toggleAutoFit)
case ".": return .perform(.toggleHidden)
case "a": return context.owner == .workspace ? .perform(.selectAllInFile) : .pass
+21 -9
View File
@@ -107,31 +107,30 @@ private struct Breadcrumb: View {
}
}
/// Git · Explorer · File · Claude: one toggle per column. Hiding a column keeps everything inside it.
/// 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"),
toggle("Explorer", .explorer),
toggle("File", .editor),
toggle("Claude", .terminal),
])
}
private func toggle(_ label: String, _ panel: Panel, column: String) -> GroupItem {
private func toggle(_ label: String, _ panel: Panel) -> 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.")
? Tooltip.stated(label + " column: ", "shown", ". Click to hide it.")
: Tooltip.stated(label + " column: ", "hidden", ". Click to show it.")
return GroupItem(label, kind: .toggle(isOn: shown), tip: tip) {
model.perform(.togglePane(panel))
}
}
}
/// Search ⌘F · Fluid ⌘L · Hidden ⌘., then `?`. Search is an action; Fluid and Hidden toggle.
/// Git ⌘G · Search ⌘F · Fluid ⌘L · Hidden ⌘., then `?`. Search is an action; the others toggle.
/// While Helder reads aloud, a Stop toggle leads the group; switching it off stops the reading.
private struct TitleToolbar: View {
let model: WorkspaceModel
@@ -140,6 +139,7 @@ private struct TitleToolbar: View {
let layout = model.layout
HStack(spacing: Metrics.toolbarIconGap) {
ButtonGroup(stop + [
git,
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),
@@ -161,6 +161,18 @@ private struct TitleToolbar: View {
.fixedSize()
}
/// N counts changed files, a file both staged and unstaged once; the dot lights while the view is open.
private var git: GroupItem {
let open = model.layout.isGitViewOpen
let count = Set(model.sourceControl?.state.changes.map(\.path) ?? []).count
let tip = open
? Tooltip.stated("Git view: ", "open", ". Click to close it (⌘G).")
: Tooltip.stated("Git view: ", "closed", ". Click to open it (⌘G).")
return GroupItem(count > 0 ? "Git \(count)" : "Git", id: "Git", keys: "⌘G", kind: .toggle(isOn: open), tip: tip) {
model.perform(.toggleGit)
}
}
private var stop: [GroupItem] {
guard model.readAloud.isReading else { return [] }
return [GroupItem("Stop", kind: .toggle(isOn: true), tip: Tooltip.stated("Read aloud: ", "playing", ". Click to stop.")) {
+21 -6
View File
@@ -8,6 +8,7 @@ struct WindowBridge: NSViewRepresentable {
/// Passed as values so a project switch re-runs `updateNSView`, which renames the window and the app.
let title: String
let hasProject: Bool
let gitViewOpen: Bool
func makeCoordinator() -> WindowCoordinator {
WindowCoordinator(model: model)
@@ -21,6 +22,7 @@ struct WindowBridge: NSViewRepresentable {
func updateNSView(_ view: BridgeView, context: Context) {
context.coordinator.updateTitle(title, hasProject: hasProject)
context.coordinator.updateGitView(open: gitViewOpen)
context.coordinator.guardClose()
}
@@ -48,6 +50,7 @@ final class WindowCoordinator: NSObject {
/// Set once the unsaved prompt said yes, so the second close goes through.
private var closeApproved = false
private var isAskingToClose = false
private var gitViewOpen = false
init(model: WorkspaceModel) {
self.model = model
@@ -103,6 +106,14 @@ final class WindowCoordinator: NSObject {
AppName.set(hasProject ? title : AppName.standard)
}
/// Opening the Git view takes the keyboard from the column behind it at once; its message field
/// takes focus a run loop later, so typing never lands in a covered terminal.
func updateGitView(open: Bool) {
defer { gitViewOpen = open }
guard open, !gitViewOpen, let window else { return }
window.makeFirstResponder(nil)
}
private func configure(_ window: NSWindow) {
window.title = model.title
window.titleVisibility = .hidden
@@ -203,19 +214,20 @@ final class WindowCoordinator: NSObject {
}
}
/// Source Control and Explorer have no text view to focus, so they hold the keyboard by clearing first responder.
/// The Explorer has no text view to focus, so it holds the keyboard by clearing first responder.
private func takeFocus(for panel: Panel, in window: NSWindow) {
if panel == .sourceControl || panel == .explorer { window.makeFirstResponder(nil) }
if panel == .explorer { window.makeFirstResponder(nil) }
}
private func handleMouseDown(_ event: NSEvent) {
guard let window, event.window === window, model.root != nil, !model.overlay.isPresented else { return }
guard let window, event.window === window, model.root != nil, !model.overlay.isPresented,
!model.layout.isGitViewOpen else { return }
let point = event.locationInWindow
let height = window.contentView?.bounds.height ?? window.frame.height
guard height - point.y > Metrics.titleBar, point.y > Metrics.statusBar else { return }
guard let panel = model.layout.panel(atX: point.x, splitterMargin: 4) else { return }
model.pointerFocused(panel)
guard panel == .sourceControl || panel == .explorer else { return }
guard panel == .explorer else { return }
// A row click pulls the keyboard out of a text view in another column; otherwise typing lands there.
DispatchQueue.main.async { [weak self, weak window] in
guard let self, let window, let view = window.firstResponder as? NSView,
@@ -235,8 +247,9 @@ final class WindowCoordinator: NSObject {
var hasSelection = false
var editorSelection: TextSelectionInfo?
var seed = ""
let gitViewOpen = model.layout.isGitViewOpen
if let text = responder as? NSTextView {
let column = column(of: text)
let column = gitViewOpen ? nil : column(of: text)
owner = .text(in: column)
let range = text.selectedRange()
hasSelection = range.length > 0
@@ -270,7 +283,9 @@ final class WindowCoordinator: NSObject {
activePanel: model.layout.activePanel,
focusZone: model.layout.focusZone,
recentFileCount: editor?.history.count ?? 0,
searchSeed: seed
searchSeed: seed,
gitViewOpen: gitViewOpen,
inGitConsole: responder is GitConsoleFieldEditor
)
}
+16 -12
View File
@@ -2,7 +2,8 @@ import AppKit
import HelderCore
import SwiftUI
/// The launcher without a project; with one, the title bar, four columns and status bar, overlays above.
/// The launcher without a project; with one, the title bar, three columns and status bar, then the Git view
/// over all of them, overlays above.
struct WorkspaceView: View {
let model: WorkspaceModel
@@ -29,20 +30,27 @@ struct WorkspaceView: View {
.zIndex(1)
StatusBarView(model: model)
}
.overlay {
// An overlay over the Git view takes the pointer from it, as from the columns.
if model.layout.isGitViewOpen {
GitView(model: model)
.environment(\.pointerLayer, model.overlay.isPresented ? .workspace : .overlay)
}
}
.overlay { OverlayHost(model: model) }
.overlay {
if model.overlay.current == .launcher { RecentProjectsOverlay(model: model).environment(\.pointerLayer, .overlay) }
}
.background(PointerRefresher(trigger: PointerRefresher.Trigger(
overlay: model.overlay.current, activePath: model.editor?.activePath, visibility: model.layout.visibility,
scale: model.layout.textScale)))
overlay: model.overlay.current, gitViewOpen: model.layout.isGitViewOpen, activePath: model.editor?.activePath,
visibility: model.layout.visibility, scale: model.layout.textScale)))
.onAppear { model.layout.windowResized(width: proxy.size.width) }
.onChange(of: proxy.size.width) { _, width in model.layout.windowResized(width: width) }
}
}
}
/// The four columns and their splitters. Every column stays mounted: a pane toggle only hides it, so the
/// The three 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 {
@@ -56,12 +64,6 @@ private struct Columns: View {
let agentFills = v.agent && !v.editor
let hiddenEditorWidth = max(editorWidth, Metrics.minEditorWidth)
HStack(spacing: 0) {
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)
@@ -114,7 +116,7 @@ extension View {
}
}
/// When a column is hidden while it holds the keyboard (a terminal, the code, the commit box), the window
/// When a column is hidden while it holds the keyboard (a terminal, the code), the window
/// takes the keyboard back, so typing never lands in a pane nobody can see.
private struct HiddenPaneFocusGuard: NSViewRepresentable {
let visibility: ColumnVisibility
@@ -145,10 +147,12 @@ private struct HiddenPaneFocusGuard: NSViewRepresentable {
}
}
/// Re-reads the pointer when what lies under a still mouse changes: an overlay, the open file, a column shown or hidden.
/// Re-reads the pointer when what lies under a still mouse changes: an overlay, the Git view, the open file,
/// a column shown or hidden.
private struct PointerRefresher: NSViewRepresentable {
struct Trigger: Equatable {
var overlay: Overlay
var gitViewOpen: Bool
var activePath: String?
var visibility: ColumnVisibility
var scale: Double
+2 -1
View File
@@ -13,7 +13,8 @@ public struct WorkspaceWindow: View {
WorkspaceView(model: model)
.frame(minWidth: Metrics.minimumWindow.width, minHeight: Metrics.minimumWindow.height)
.background(Palette.editor)
.background(WindowBridge(model: model, title: model.title, hasProject: model.root != nil))
.background(WindowBridge(model: model, title: model.title, hasProject: model.root != nil,
gitViewOpen: model.layout.isGitViewOpen))
.preferredColorScheme(.dark)
.focusedSceneValue(\.workspace, model)
.task { await model.start() }