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
+12
-64
@@ -4,7 +4,8 @@
|
||||
//
|
||||
// #17 (S1.1): the Posts pane — library column mirroring the Home's posts/
|
||||
// on disk. #18: lifecycle — New Post draft, ⌘S first-write/save, rename,
|
||||
// trash; TextEditor stub until #19–#21, mentor column (#14).
|
||||
// trash. #19: the TextKit2 editor core (PostEditorView) replaces the stub;
|
||||
// mentor column (#14).
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
@@ -92,7 +93,7 @@ struct PostsPaneView: View {
|
||||
.padding(.bottom, 7)
|
||||
ForEach(grouped) { post in
|
||||
PostRow(post: post, selected: post.id == model.selectedPostID) {
|
||||
model.select(post.id)
|
||||
model.select(post.id, home: home)
|
||||
}
|
||||
.contextMenu {
|
||||
Button("Rename…") { renamingPost = post }
|
||||
@@ -124,29 +125,23 @@ struct PostsPaneView: View {
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
|
||||
// MARK: Editor column (stub until #19)
|
||||
// MARK: Editor column (#19: TextKit2 editor core)
|
||||
|
||||
private var editorColumn: some View {
|
||||
VStack(spacing: 0) {
|
||||
if let draft = model.draft {
|
||||
EditorStub(
|
||||
initialText: draft.text,
|
||||
crumb: "unsaved draft — no folder until first save",
|
||||
save: { text in
|
||||
model.updateDraft(text)
|
||||
PostEditorView(
|
||||
session: nil,
|
||||
draftText: draft.text,
|
||||
draftEdited: { model.updateDraft($0) },
|
||||
draftSave: {
|
||||
model.saveDraft(home: home)
|
||||
},
|
||||
)
|
||||
.id("draft")
|
||||
} else if let post = model.posts.first(where: { $0.id == model.selectedPostID }) {
|
||||
// ponytail: readBody is one small file, sync, per selection
|
||||
// change — #19's editor owns async loading when it lands.
|
||||
EditorStub(
|
||||
initialText: PostStore.readBody(id: post.id, home: home) ?? "",
|
||||
crumb: "posts / \(post.id) / post.md",
|
||||
save: { text in model.saveSelected(body: text, home: home) },
|
||||
)
|
||||
.id(post.id)
|
||||
} else if let session = model.session, session.postID == model.selectedPostID {
|
||||
PostEditorView(session: session, draftText: nil)
|
||||
.id(session.postID)
|
||||
} else {
|
||||
VStack(spacing: 10) {
|
||||
Image(systemName: "square.and.pencil")
|
||||
@@ -175,53 +170,6 @@ struct PostsPaneView: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// #18 stub editor (#62): plain TextEditor in the placeholder slot; ⌘S is
|
||||
/// the first-write trigger (lazy folder + slug + stamp). Throwaway at the
|
||||
/// view layer — #19's TextKit2 editor replaces it in place; the lifecycle
|
||||
/// machinery lives in PostsModel/PostStore and survives the swap.
|
||||
private struct EditorStub: View {
|
||||
/// Typed text is local @State — disk is written only on save; `.id()` at
|
||||
/// the call site swaps identity (and thus reloads) per post/draft.
|
||||
let crumb: String
|
||||
let save: (String) -> Void
|
||||
@State private var text: String
|
||||
|
||||
init(
|
||||
initialText: String,
|
||||
crumb: String,
|
||||
save: @escaping (String) -> Void,
|
||||
) {
|
||||
self.crumb = crumb
|
||||
self.save = save
|
||||
_text = State(initialValue: initialText)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
HStack {
|
||||
Text(crumb)
|
||||
.font(.system(size: 11, design: DesignTokens.mono))
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.head)
|
||||
Spacer()
|
||||
Button("Save") { save(text) }
|
||||
.keyboardShortcut("s", modifiers: .command)
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.frame(minHeight: 40)
|
||||
.overlay(alignment: .bottom) {
|
||||
Rectangle().fill(DesignTokens.border).frame(height: 1)
|
||||
}
|
||||
TextEditor(text: $text)
|
||||
.font(.system(size: 15, design: DesignTokens.serif))
|
||||
.scrollContentBackground(.hidden)
|
||||
.padding(EdgeInsets(top: 20, leading: 24, bottom: 20, trailing: 24))
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
|
||||
/// #60: Explicit Rename dialog — asks the new Title (not a slug).
|
||||
private struct RenamePostSheet: View {
|
||||
let rename: (String) -> Void
|
||||
|
||||
Reference in new issue
Block a user