fix(editor): editor owns file drops on macOS 27.2

Dropping an image file on the prose editor pasted the file path
instead of ingesting it (#141 follow-up, unticketed; dogfood on
macOS 27.2.1). #141 was field-verified on 27.0.1, where the
window-level SwiftUI dropDestination starved every deeper
destination; 27.2 routes a drag to the deepest destination, and a
live NSTextView registers itself for drag types, so its stock
performDragOperation pasted the path and the window destination
never fired — the same for a markdown file dropped on the editor.

The editor text views now share a FileDropTextView base that owns
the drops landing on them: URL-bearing drags route (never super) —
the prose editor through the one new AppGateState.routeFileDrop
(Cold Turkey guard, markdown → guest, anything else → ingestDrop),
which the window destination also uses for drops landing outside
the editor; the outline rows bounce; text-only drags keep the stock
drop; the pasteboard probe is memoized per changeCount. A web URL
refuses with the type strip, a vanished file refuses as missing.

+9 tests (a real NSDraggingInfo mock drives the overrides; the
router's guest/lock/ingest branches pinned), all flip-verified.
Finish-audit: three reviewers; the text-drag regression and the
outline rows' identical exposure fixed, two pre-existing ceilings
deferred in the devlog. Rail 729/729, swiftformat 0/153, swiftlint 0.
This commit is contained in:
AlexKucera committed 2026-12-03 16:36:47 +01:00
1 parent 64a7eaa37e
commit 46e87e678c
15 files changed
+529 -60

No files matched your search

+15 -6
View File
@@ -182,6 +182,7 @@ struct PostEditorView: View {
focused: gate.isFocused,
caretHint: flipBackCaret,
dropBridge: gate.proseDrop,
routeDrop: { gate.routeFileDrop($0) },
// #162: the Cold Turkey word feed.
onTextChange: { gate.writingLock.feed(text: $0) },
)
@@ -196,6 +197,7 @@ struct PostEditorView: View {
},
caretHint: flipBackCaret,
dropBridge: gate.proseDrop,
routeDrop: { gate.routeFileDrop($0) },
// #162: the Cold Turkey word feed.
onTextChange: { gate.writingLock.feed(text: $0) },
)
@@ -338,8 +340,8 @@ private struct SaveStateDot: View {
// MARK: - TextKit2 surface (the lifted spike pane)
/// #141: the SwiftUI drop target's handle down to the live prose text
/// view (weak — dies with the editor surface).
/// #141: the window-level SwiftUI destination's handle down to the live
/// prose text view (weak — dies with the editor surface).
@MainActor
final class ProseDropBridge {
weak var textView: ProseListTextView?
@@ -366,10 +368,11 @@ struct ProseTextView: NSViewRepresentable {
/// only (drafts have no folder until first save; the external guest
/// isn't a piece). Nil = image drags refuse loudly.
var ingestFolder: URL?
/// #141: the drop bridge — the WINDOW-level SwiftUI drop target
/// reaches this text view through it (app-scoped, passed down from
/// the gate at both call sites — never optional).
/// #141: the window-level SwiftUI destination's handle to the live
/// view (drops landing OUTSIDE the editor); the gate's router for drops
/// landing ON it — both handed down from the gate at both call sites.
var dropBridge: ProseDropBridge
var routeDrop: ([URL]) -> Bool
init(
session: EditorSession,
@@ -377,6 +380,7 @@ struct ProseTextView: NSViewRepresentable {
focused: Bool = false,
caretHint: (location: Int, token: Int)? = nil,
dropBridge: ProseDropBridge,
routeDrop: @escaping ([URL]) -> Bool,
onTextChange: ((String) -> Void)? = nil,
) {
self.session = session
@@ -386,6 +390,7 @@ struct ProseTextView: NSViewRepresentable {
self.onTextChange = onTextChange
ingestFolder = session.postID != nil ? session.folderURL : nil
self.dropBridge = dropBridge
self.routeDrop = routeDrop
}
init(
@@ -395,6 +400,7 @@ struct ProseTextView: NSViewRepresentable {
onEdit: @escaping (String) -> Void,
caretHint: (location: Int, token: Int)? = nil,
dropBridge: ProseDropBridge,
routeDrop: @escaping ([URL]) -> Bool,
onTextChange: ((String) -> Void)? = nil,
) {
self.draft = draft
@@ -404,6 +410,7 @@ struct ProseTextView: NSViewRepresentable {
self.caretHint = caretHint
self.onTextChange = onTextChange
self.dropBridge = dropBridge
self.routeDrop = routeDrop
}
/// Cursor state snapshot from the live view (#66).
@@ -430,7 +437,8 @@ struct ProseTextView: NSViewRepresentable {
func makeNSView(context: Context) -> NSScrollView {
let tv = ProseListTextView() // #115: list shortcuts + folds on the plain surface
tv.ingestFolder = ingestFolder // #141: image-drop ingest (nil on drafts/guests)
dropBridge.textView = tv // #141: the SwiftUI drop target's handle
dropBridge.textView = tv // #141: the window destination's handle
tv.onFileDrop = routeDrop // #141: the view's own drag handlers route here
tv.isRichText = false // plain source of truth; attributes are presentation
tv.allowsUndo = true
tv.isAutomaticQuoteSubstitutionEnabled = false
@@ -485,6 +493,7 @@ struct ProseTextView: NSViewRepresentable {
tv.isContinuousSpellCheckingEnabled = spellChecking
tv.ingestFolder = ingestFolder // #141: cheap idempotent set
dropBridge.textView = tv // #141: idempotent re-point
tv.onFileDrop = routeDrop // #141: idempotent re-point
// #21: the ground follows focus in/out without a remount.
let ground = focused ? NSColor(DesignTokens.background) : NSColor(DesignTokens.surface)
tv.backgroundColor = ground