before the great git rework

This commit is contained in:
2026-10-30 11:27:44 +01:00
parent 9bdda896af
commit b9c03a7637
45 changed files with 70 additions and 562 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ private struct EditorWorkspace: View {
/// What the column shows with no file open: only what works without one.
struct EditorEmptyState: View {
private let keys: [(String, String)] = [
("Open folder", "⌘O"), ("Recent projects", "⇧⌘O"), ("Search files & content", "⌘F"), ("Project note", "⌘N"),
("Open folder", "⌘O"), ("Recent projects", "⇧⌘O"), ("Search files & content", "⌘F"),
]
var body: some View {
@@ -1,45 +0,0 @@
import SwiftUI
/// ⌘N: the project's plain-text note. Closing it in any way saves it.
struct NoteOverlay: View {
let note: NoteStore
var onPassOn: () -> Void
var onClose: () -> Void
var body: some View {
OverlayShell(.sized(width: 780), onDismiss: onClose) {
VStack(spacing: 0) {
OverlayHeader(systemImage: "note.text", title: "Note", detail: NoteStore.fileName) {
Button(action: onPassOn) {
HStack(spacing: 8) {
Text("To the agent")
Keycap("⌘P", style: .onAmber, small: true)
}
}
.buttonStyle(.primary)
}
OverlayTextEditor(text: Binding(get: { note.text }, set: { note.text = $0 }),
placeholder: "Anything you want to keep next to this project…", onKey: handle)
.frame(maxWidth: .infinity, maxHeight: .infinity)
Text("saved on focus loss · \(note.characterCount) characters")
.typeRole(Typography.meta)
.foregroundStyle(Palette.text4)
.padding(.horizontal, 20)
.frame(maxWidth: .infinity, alignment: .leading)
.frame(height: 34)
.hairline(.top)
}
.frame(maxHeight: .infinity)
}
.onDisappear { Task { await note.save() } }
}
private func handle(_ key: OverlayKey) -> Bool {
switch key {
case .commandP: onPassOn()
case .escape: onClose()
default: return false
}
return true
}
}
@@ -32,10 +32,6 @@ public struct OverlayHost: View {
}
case .shortcuts:
ShortcutsOverlay(onClose: dismiss)
case .note:
if let note = model.note {
NoteOverlay(note: note, onPassOn: { model.perform(.passNote) }, onClose: dismiss)
}
case .cleanCopy:
if let cleanCopy = model.cleanCopy {
CleanCopyOverlay(store: cleanCopy, onCopy: { model.perform(.copyCleanCopy) }, onClose: dismiss)
@@ -28,8 +28,6 @@ public enum ShortcutCatalog {
]),
ShortcutGroup(title: "Agent", rows: [
ShortcutRow(keys: ["⌘", "→"], label: "Pass the selection to the agent"),
ShortcutRow(keys: ["⌘", "N"], label: "Open the project note"),
ShortcutRow(keys: ["⌘", "P"], label: "Pass on the whole note"),
]),
ShortcutGroup(title: "Git", rows: [
ShortcutRow(keys: ["⌘", "C"], label: "Focus the commit message"),
+1 -1
View File
@@ -32,7 +32,7 @@ public final class AppDelegate: NSObject, NSApplicationDelegate {
false
}
/// ⌘Q asks about unsaved files in every window first, and writes each note and session before quitting.
/// ⌘Q asks about unsaved files in every window first, and writes each session before quitting.
public func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
let models = WorkspaceRegistry.models
guard !models.isEmpty else { return .terminateNow }
+1 -8
View File
@@ -47,8 +47,6 @@ public enum Command: Equatable, Sendable {
/// ⌘F; the seed is the first line of the current selection.
case showSearch(seed: String)
/// ⌘N
case showNote
/// `?`
case showShortcuts
/// ⇧⌘O: the other recent projects.
@@ -57,7 +55,7 @@ public enum Command: Equatable, Sendable {
case showRecentFiles(initialSelection: Int)
/// Right-click or ⌘→ on a row; `anchor` is in window coordinates.
case showContextMenu(ContextTarget, anchor: CGPoint)
/// Esc: closes the one open overlay, with its own close behaviour (the note saves, Diff restores the mode).
/// Esc: closes the one open overlay, with its own close behaviour (Diff restores the mode).
case dismissOverlay
/// The confirm overlay's yes.
case confirmPending
@@ -119,11 +117,6 @@ public enum Command: Equatable, Sendable {
/// ⌘C without a selection, outside a terminal
case focusCommitMessage
// MARK: Note
/// ⌘P while the note is open.
case passNote
// MARK: Clean copy
/// The clean-copy popup's Copy and ⌘↩: copies its text and closes it.
-2
View File
@@ -90,8 +90,6 @@ struct HelderCommands: Commands {
Divider()
Button("Search") { workspace?.perform(.showSearch(seed: "")) }
.keyboardShortcut("f", modifiers: .command)
Button("Project Note") { workspace?.perform(.showNote) }
.keyboardShortcut("n", modifiers: .command)
Button("Keyboard Shortcuts") { workspace?.perform(.showShortcuts) }
Divider()
Button("Actual Size") { workspace?.perform(.zoom(.reset)) }
-5
View File
@@ -76,7 +76,6 @@ public struct KeyContext: Equatable, Sendable {
/// The overlay kinds the router tells apart.
public enum OverlayKind: Equatable, Sendable {
case none
case note
/// The full-screen Diff: the workspace shortcuts keep working over it. `busy` while its own
/// menu or pass-on prompt is open; those then own every key.
case diff(busy: Bool)
@@ -86,7 +85,6 @@ public enum OverlayKind: Equatable, Sendable {
public init(_ overlay: Overlay, diffBusy: Bool = false) {
switch overlay {
case .none: self = .none
case .note: self = .note
case .diff: self = .diff(busy: diffBusy)
default: self = .other
}
@@ -116,8 +114,6 @@ public enum KeyRouter {
case .none: break
case .diff:
if press == .cmd(.character("a")) { return .pass }
case .note:
return press == .cmd(.character("p")) ? .perform(.passNote) : .pass
case .other: return .pass
}
@@ -177,7 +173,6 @@ public enum KeyRouter {
switch c {
case "f": return .perform(.showSearch(seed: context.searchSeed))
case "p": return .perform(.push)
case "n": return .perform(.showNote)
case "s": return .perform(.save)
case "m": return .perform(.cycleMode)
case "w": return .perform(.closeFileOrWindow)
+1 -3
View File
@@ -131,7 +131,7 @@ private struct PaneToggles: View {
}
}
/// Search ⌘F · Fluid ⌘L · Hidden ⌘. · Note ⌘N, then `?`. Search and Note are actions; Fluid and Hidden toggle.
/// Search ⌘F · Fluid ⌘L · Hidden ⌘., then `?`. Search is an action; Fluid and Hidden toggle.
/// While Helder reads aloud, a Stop toggle leads the group; switching it off stops the reading.
private struct TitleToolbar: View {
let model: WorkspaceModel
@@ -154,8 +154,6 @@ private struct TitleToolbar: View {
: 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) }
.tip("Keyboard shortcuts.", edge: .trailing)
+1 -1
View File
@@ -74,7 +74,7 @@ final class WindowCoordinator: NSObject {
window.delegate = closeGuard
}
/// The first close only asks: unsaved files prompt, the note and session are written, then the window closes.
/// The first close only asks: unsaved files prompt, the session is written, then the window closes.
private func shouldClose(_ window: NSWindow) -> Bool {
if closeApproved { return true }
guard !isAskingToClose else { return false }
-66
View File
@@ -1,66 +0,0 @@
import Foundation
import HelderServices
import Observation
@Observable
@MainActor
public final class NoteStore {
public static let fileName = NotesService.fileName
public var text = ""
/// What is on disk, so a save without edits does not touch the file and wake the watcher.
public private(set) var savedText = ""
/// Raises a toast; the model wires it to `ToastStore`.
@ObservationIgnored public var notify: ((String, String?) -> Void)?
@ObservationIgnored private let notes: NotesServicing
public init(notes: NotesServicing) {
self.notes = notes
}
public var isDirty: Bool { text != savedText }
public var characterCount: Int { text.count }
public func load() async {
let loaded = await notes.read()
text = loaded
savedText = loaded
}
/// Picks up an outside edit of the note file; unsaved typing always wins.
public func reloadIfClean() async {
guard !isDirty else { return }
let loaded = await notes.read()
guard !isDirty, loaded != savedText else { return }
text = loaded
savedText = loaded
}
/// Saves when the text changed; called on window blur, on close and when the overlay closes.
/// Returns false when the write failed.
@discardableResult
public func save() async -> Bool {
guard isDirty else { return true }
let snapshot = text
// Marked saved before the write, so a second blur during the write does not write again.
let previous = savedText
savedText = snapshot
do {
try await notes.write(snapshot)
return true
} catch {
if savedText == snapshot { savedText = previous }
Log.error("notes", "save failed: \(error.localizedDescription)")
notify?("Save failed", Self.fileName)
return false
}
}
/// The trimmed note for ⌘P, or nil when it is empty.
public var passableText: String? {
let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
return trimmed.isEmpty ? nil : trimmed
}
}
+1 -3
View File
@@ -88,8 +88,6 @@ public enum Overlay: Equatable {
case search(seed: String)
/// `?`: the keyboard reference.
case shortcuts
/// ⌘N: the project note.
case note
/// Text the agent wrote to `.clean-copy`, to edit and copy.
case cleanCopy
case diff(DiffOverlayRequest)
@@ -110,7 +108,7 @@ public enum Overlay: Equatable {
public final class OverlayStore {
public private(set) var current = Overlay.none
/// Called with the old and new overlay on every change, however it happened, so closing
/// behaviour (the note saves, the Diff restores the mode) runs even when another overlay takes over.
/// behaviour (the Diff restores the mode) runs even when another overlay takes over.
@ObservationIgnored public var onChange: ((_ old: Overlay, _ new: Overlay) -> Void)?
public init() {}
@@ -8,8 +8,6 @@ extension WorkspaceModel {
func overlayChanged(from old: Overlay, to new: Overlay) {
switch old {
case .note:
if let note { track { await note.save() } }
case .diff:
editor?.closeDiff()
default:
@@ -103,7 +101,7 @@ extension WorkspaceModel {
}
}
// MARK: Editor and the note
// MARK: Editor
func passSelection(_ info: TextSelectionInfo?) {
guard let editor, let path = editor.activePath else { return }
@@ -115,14 +113,6 @@ extension WorkspaceModel {
}
}
/// ⌘P with the note open: the whole note goes to the agent, and the note closes so the text is seen landing.
func passNote() {
guard let note, let text = note.passableText else { return }
terminal.insertIntoAgent(text: text)
overlay.dismiss()
toasts.show("Note passed to agent", detail: NoteStore.fileName)
}
func editorSelectionFirstLine() -> String {
guard let editor, let path = editor.activePath, let selection = editor.selection, selection.path == path else { return "" }
let lines = editor.text(for: path).split(separator: "\n", omittingEmptySubsequences: false)
@@ -17,11 +17,10 @@ extension WorkspaceModel {
isReady = true
}
/// Asks about every unsaved file, then writes the note and the session.
/// Asks about every unsaved file, then writes the session.
/// False when the user cancelled: the window or project must stay.
public func prepareToClose() async -> Bool {
if let editor, !(await editor.resolveUnsaved()) { return false }
await note?.save()
await editor?.persist()
return true
}
@@ -66,9 +65,6 @@ extension WorkspaceModel {
wire(editor, symbols: services.symbols)
self.editor = editor
let note = NoteStore(notes: services.notes)
note.notify = notify
self.note = note
cleanCopy = CleanCopyStore(files: services.files)
terminal = TerminalStore(projectRoot: root.path)
wireTerminal()
@@ -101,12 +97,11 @@ extension WorkspaceModel {
recentProjects = await app.recentProjects.list()
guard generation == current else { return }
launcher = LauncherList(recents: recentProjects, excluding: root.path)
let sourceControl = sourceControl, explorer = explorer, note = note, editor = editor, cleanCopy = cleanCopy
let sourceControl = sourceControl, explorer = explorer, editor = editor, cleanCopy = cleanCopy
async let git: Void = sourceControl?.refresh() ?? ()
async let tree: Void = explorer?.reload() ?? ()
async let loaded: Void = note?.load() ?? ()
async let baseline: Void = cleanCopy?.loadBaseline() ?? ()
_ = await (git, tree, loaded, baseline)
_ = await (git, tree, baseline)
await editor?.restore(restoreSession: config.session.restoreOnLaunch)
guard generation == current else { return }
startWatcher(root)
@@ -115,7 +110,7 @@ extension WorkspaceModel {
}
/// Stops the watchers and polling, waits for the work still running against this project,
/// then stops reading aloud, saves the note and the session and ends the terminals.
/// then stops reading aloud, saves the session and ends the terminals.
func closeProject() async {
watcher?.stop()
watcher = nil
@@ -134,7 +129,6 @@ extension WorkspaceModel {
for task in running { await task.value }
readAloud.stop()
await editor?.flushAutoSaves()
await note?.save()
await editor?.persist()
terminal.terminateAll()
}
@@ -15,7 +15,7 @@ extension WorkspaceModel {
/// Reacts to a disk change from the watcher: project and git events gather into one debounced refresh.
public func handle(_ event: WatchEvent) async {
switch event {
case .project: scheduleRefresh([.git, .tree, .symbols, .openFiles, .note])
case .project: scheduleRefresh([.git, .tree, .symbols, .openFiles])
case .git: scheduleRefresh(.git)
case .config: await reloadConfig()
case .cleanCopy: await cleanCopyChanged()
@@ -61,7 +61,7 @@ extension WorkspaceModel {
/// Reads the stores once up front, so a pass that outlives a project switch only touches the old project.
func run(_ scope: RefreshScope) async {
let sourceControl = sourceControl, explorer = explorer, editor = editor, note = note
let sourceControl = sourceControl, explorer = explorer, editor = editor
let current = generation
if scope.contains(.symbols) {
await services?.symbols.invalidate()
@@ -70,8 +70,7 @@ extension WorkspaceModel {
async let git: Void = scope.contains(.git) ? (sourceControl?.refresh() ?? ()) : ()
async let tree: Void = scope.contains(.tree) ? (explorer?.reload() ?? ()) : ()
async let files: Void = scope.contains(.openFiles) ? (editor?.filesChanged(nil) ?? ()) : ()
async let notes: Void = scope.contains(.note) ? (note?.reloadIfClean() ?? ()) : ()
_ = await (git, tree, files, notes)
_ = await (git, tree, files)
}
/// Restarts the countdown on every change, so a burst of writes loads the class list once.
+2 -9
View File
@@ -41,8 +41,6 @@ public struct RefreshScope: OptionSet, Sendable {
public static let symbols = RefreshScope(rawValue: 4)
/// The open file and every unsaved buffer pick up the disk text; unsaved edits are kept.
public static let openFiles = RefreshScope(rawValue: 8)
/// The project note picks up an outside edit when it has no unsaved typing.
public static let note = RefreshScope(rawValue: 16)
}
/// A list row whose on-screen frame the ⌘→ menu anchors to.
@@ -84,7 +82,6 @@ public final class WorkspaceModel {
public internal(set) var explorer: ExplorerStore?
public internal(set) var editor: EditorStore?
public internal(set) var terminal: TerminalStore
public internal(set) var note: NoteStore?
public internal(set) var cleanCopy: CleanCopyStore?
@ObservationIgnored public let app: AppServices
@@ -122,7 +119,7 @@ public final class WorkspaceModel {
if let root = self.root { attach(root) }
}
/// Loads the recents and, with a project, its config, git, tree, note and session; then starts the watchers.
/// Loads the recents and, with a project, its config, git, tree and session; then starts the watchers.
public func start() async {
guard !hasStarted else { return }
hasStarted = true
@@ -136,7 +133,6 @@ public final class WorkspaceModel {
public func perform(_ command: Command) {
switch command {
case let .showSearch(seed): overlay.present(.search(seed: seed.isEmpty ? editorSelectionFirstLine() : seed))
case .showNote: overlay.present(.note)
case .showShortcuts: overlay.present(.shortcuts)
case .showRecentProjects: showRecentProjects()
case let .showRecentFiles(index): overlay.present(.recentFiles(initialSelection: index))
@@ -188,7 +184,6 @@ public final class WorkspaceModel {
layout.focus(.sourceControl)
focusRequest = FocusRequest(.commitMessage)
case .passNote: passNote()
case .copyCleanCopy: copyCleanCopy()
case .stopReading: readAloud.stop()
@@ -251,11 +246,9 @@ public final class WorkspaceModel {
rowFrames[key] = frame
}
/// Saves the note when the window loses focus.
/// Remembers the window lost focus, so coming back can flash branch · project.
public func windowDidResignKey() {
resignedKey = true
guard let note else { return }
track { await note.save() }
}
/// Coming back to a window flashes branch · project, so the right window is obvious; launch never does.
@@ -9,17 +9,15 @@ public struct WorkspaceServices {
public var search: SearchServicing
public var symbols: SymbolServicing
public var config: ConfigServicing
public var notes: NotesServicing
public var recentFiles: RecentFilesStoring
public init(git: GitServicing, files: FileServicing, search: SearchServicing, symbols: SymbolServicing,
config: ConfigServicing, notes: NotesServicing, recentFiles: RecentFilesStoring) {
config: ConfigServicing, recentFiles: RecentFilesStoring) {
self.git = git
self.files = files
self.search = search
self.symbols = symbols
self.config = config
self.notes = notes
self.recentFiles = recentFiles
}
@@ -32,7 +30,6 @@ public struct WorkspaceServices {
search: search,
symbols: SymbolService(root: root, config: config),
config: config,
notes: NotesService(root: root),
recentFiles: RecentFilesStore(root: root)
)
}