feat(posts): import & external markdown — S1.1 (#22)
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
External .md/.markdown opens and edits as-is in a single guest slot (File > Open... Cmd+O, drag-onto-window): SessionTarget extends EditorSession to write in place verbatim, no cursor sidecar, the #67 conflict alert reused for foreign files. Import... (Shift+Cmd+O) copies multi-select files in as Posts behind ONE Origin ask (writer default, immutable); external frontmatter keys ride verbatim with pass_state/origin set; slug/collision machinery shared with writeNew. Audit fixes folded in: BOM stripped + CRLF normalized at the trust boundary (a CRLF pair is one Swift grapheme — \n splits saw one line); unreadable files refuse to open (loadFailed — a failed read never becomes a write); dropped web links and severed symlinks guarded; ~24 lines of reviewer-flagged dead weight removed. 7 new tests; full unit + UI suite green; swiftlint clean. Map #22 stays open pending the live calibration pass (#88 posture).
This commit is contained in:
1 parent
683d697367
commit
0f1c4ef4fe
14 files changed
+691
-49
No files matched your search
@@ -5,6 +5,7 @@
|
||||
// Created by Alexander Kucera on 26.08.26.
|
||||
//
|
||||
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
/// App-scoped gate state — raised once per app-launch, first window only (ticket #41).
|
||||
@@ -83,6 +84,13 @@ struct MuseionApp: App {
|
||||
CommandGroup(replacing: .appInfo) {
|
||||
OpenAboutButton()
|
||||
}
|
||||
// #91/#94: File ▸ Open… (⌘O) and Import… (⇧⌘O) join the system
|
||||
// File menu after New — never CommandMenu("File"), which doubles
|
||||
// it (#84 trap).
|
||||
CommandGroup(after: .newItem) {
|
||||
OpenExternalButton(gate: gate)
|
||||
ImportFilesButton(gate: gate)
|
||||
}
|
||||
// #77: spellcheck posture — Edit ▸ Check Spelling While Typing,
|
||||
// default off (Neo posture: on when asked). Explicit rather than
|
||||
// relying on the stock submenu's presence in a WindowGroup app.
|
||||
@@ -143,13 +151,58 @@ private struct FocusModeToggle: View {
|
||||
var body: some View {
|
||||
// Entry guard: nothing open = nothing to focus on. Exit stays armed
|
||||
// even then (trashing the open post while focused must not trap).
|
||||
// #92: the external guest counts as open too.
|
||||
let canFocus = gate.isFocused || gate.posts.session != nil || gate.posts.draft != nil
|
||||
|| gate.posts.externalSession != nil
|
||||
Button("Toggle Focus Mode") { gate.isFocused.toggle() }
|
||||
.keyboardShortcut("f", modifiers: [.command, .option])
|
||||
.disabled(!canFocus)
|
||||
}
|
||||
}
|
||||
|
||||
/// #91: File ▸ Open… (⌘O) — NSOpenPanel (the Settings Home picker pattern),
|
||||
/// .md/.markdown only (#96). Opens into the single external guest slot.
|
||||
private struct OpenExternalButton: View {
|
||||
let gate: AppGateState
|
||||
|
||||
var body: some View {
|
||||
Button("Open…") {
|
||||
if let url = pickMarkdown(multiple: false, message: "Opens the file as-is — Museion never converts or moves it.").first {
|
||||
gate.posts.openExternal(url)
|
||||
}
|
||||
}
|
||||
.keyboardShortcut("o", modifiers: .command)
|
||||
}
|
||||
}
|
||||
|
||||
/// #94: File ▸ Import… (⇧⌘O) — multi-select, .md/.markdown only; ONE Origin
|
||||
/// ask per batch, then copy in as Posts.
|
||||
private struct ImportFilesButton: View {
|
||||
let gate: AppGateState
|
||||
|
||||
var body: some View {
|
||||
Button("Import…") {
|
||||
let urls = pickMarkdown(multiple: true, message: "Imports copies as Posts — the original files are untouched.")
|
||||
if !urls.isEmpty {
|
||||
gate.posts.stageImport(urls)
|
||||
}
|
||||
}
|
||||
.keyboardShortcut("o", modifiers: [.command, .shift])
|
||||
}
|
||||
}
|
||||
|
||||
/// The shared NSOpenPanel for both File-menu entries (#91/#94): local
|
||||
/// .md/.markdown files only.
|
||||
private func pickMarkdown(multiple: Bool, message: String) -> [URL] {
|
||||
let panel = NSOpenPanel()
|
||||
panel.canChooseFiles = true
|
||||
panel.canChooseDirectories = false
|
||||
panel.allowsMultipleSelection = multiple
|
||||
panel.allowedContentTypes = PostStore.openableTypes
|
||||
panel.message = message
|
||||
return panel.runModal() == .OK ? panel.urls : []
|
||||
}
|
||||
|
||||
/// #50: reveals `~/Library/Application Support/Museion/Backups` in Finder —
|
||||
/// restore is manual Finder copy-back in v1 (help doc describes it).
|
||||
private struct OpenBackupFolderButton: View {
|
||||
|
||||
Reference in new issue
Block a user