feat(editor): land editor core — open, edit, autosave (S1.2)
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
Posts open into the TextKit2 surface (ADR-0010 mode B) lifted from the proven spike: styled source, scaled headings, dimmed syntax, native undo/IME. One EditorSession per open post drives a ~1 s debounced autosave (flush on selection change, window close, app quit; ⌘S immediate), the Saved/Saving/Failed dot, and the per-post .museion-state.json cursor sidecar that dies with the folder. External edits raise an explicit Reload/Keep-Local alert — the debounce never answers it for the writer, and drafts keep the lazy-folder first-⌘S rule (#62). Reviewer fanout fixes folded in: session teardown at every lifecycle exit (rename flushes before the folder move; trash cancels the debounce), draft ⌘S continues in place, conflict holds the debounce, rescan's disk read off-main, ~35 lines of dead code out. Closes #19
This commit is contained in:
1 parent
530f852f75
commit
f2953ee07e
13 files changed
+893
-87
No files matched your search
@@ -115,6 +115,34 @@ nonisolated enum PostStore {
|
||||
return splitFrontmatter(text).body
|
||||
}
|
||||
|
||||
// MARK: Cursor-state sidecar (#66)
|
||||
|
||||
/// Cursor state for one post: selection + scroll, `.museion-state.json`
|
||||
/// in the post folder — Finder-invisible, human-diffable, dies with the
|
||||
/// folder on Trash. Drafts skip it (#62).
|
||||
struct CursorState: Codable, Equatable {
|
||||
var selectionLocation: Int = 0
|
||||
var selectionLength: Int = 0
|
||||
var scrollOffset: Double = 0
|
||||
}
|
||||
|
||||
private static func stateURL(id: String, home: URL) -> URL {
|
||||
home.appendingPathComponent("posts/\(id)/.museion-state.json")
|
||||
}
|
||||
|
||||
/// Read the sidecar; nil when absent or corrupt (a fresh cursor is fine).
|
||||
static func readCursor(id: String, home: URL) -> CursorState? {
|
||||
guard let data = try? Data(contentsOf: stateURL(id: id, home: home)) else { return nil }
|
||||
return try? JSONDecoder().decode(CursorState.self, from: data)
|
||||
}
|
||||
|
||||
/// Write the sidecar. Best-effort by design — a failed cursor write must
|
||||
/// never read as a failed content save, so failures are swallowed here.
|
||||
static func writeCursor(_ state: CursorState, id: String, home: URL) {
|
||||
guard let data = try? JSONEncoder().encode(state) else { return }
|
||||
try? data.write(to: stateURL(id: id, home: home), options: .atomic)
|
||||
}
|
||||
|
||||
/// Explicit Rename (#60): rewrite the `# Title` line as the first
|
||||
/// non-empty body line, then move the folder to the new slug. The file
|
||||
/// stays `post.md`; a title that slugs to the current id only retitles.
|
||||
|
||||
Reference in new issue
Block a user