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:
1 parent
64a7eaa37e
commit
46e87e678c
15 files changed
+529
-60
No files matched your search
@@ -44,7 +44,7 @@ Conventions every suite follows. Per-suite pin inventories are NOT kept here —
|
||||
- `FixCardApplyTests` — fix-card apply/skip/done lifecycle.
|
||||
- `PostsModelTests`, `PassRunTests`, `BlindReadTests`, `EngineLifecycleTests`, `SessionLifecycleTests`, `SessionScopeTests`, `TranscriptRailTests` — model orchestration over the scripted in-process engine (#178): passes, blind read, per-surface engines, session lifecycle, scoped hosting, the typed transcript rail (#177 — speaker/notice type facts through the scripted engine, prefix-free invariant, append-seam classifiers), and the #179 write-rail pins in PostsModelTests (write → one library refresh + strip cleared; failed write owns the strip; nil-Home refuses cleanly; import batch keeps per-file strip messages; mid-pass Home repoint refuses the advance — `endHeldPrompt` is the rig hook that ends a held turn normally, polled to via `hasHeldPrompt` first: `runningPass` flips before the one-shot engine parks its prompt, so firing into that window false-fails under load).
|
||||
- `DeslopLintTests` (with the `DeslopLintWiringTests` member) — native lint findings, config story, emit loop.
|
||||
- `EditorSessionTests`, `ReadingPresenterTests`, `ProsePresenterTests`, `FocusModeTests`, `ImportExternalTests`, `ImageIngestTests` — editor session, reading pipeline, editing-surface parity, focus math, import + image ingest.
|
||||
- `EditorSessionTests`, `ReadingPresenterTests`, `ProsePresenterTests`, `FocusModeTests`, `ImportExternalTests`, `ImageIngestTests` — editor session, reading pipeline, editing-surface parity, focus math, import, image ingest + the 27.2 drag-routing seam (`DragInfoStub`, the suite's NSDraggingInfo mock: a Finder-shaped drag routes through the text view and never pastes the path; text-only drags keep the stock drop; outline rows bounce; the probe follows `changeCount`; web URLs and vanished files refuse with the right notice) + the one router's pins (guest, Cold Turkey refusal, ingest hand-off, mixed refusal).
|
||||
- `OutlineTreeTests`, `OutlinePresenterTests`, `OutlineDragTests`, `EscEventProbeTests` — outliner model, projection, drag plumbing, Esc delivery probe.
|
||||
- `ProseListTests`, `ProseRekeyTests` — prose list model + fold rendering, fold rekey pipeline.
|
||||
- `SettingsModelTests`, `SettingsModelWritePathTests`, `HermesSettingsWriterTests`, `ProviderProbeTests`, `ProviderProbeTransportTests`, `ProviderCredentialTests` — settings model, real CLI write path, probe decode + request builders, the #181 ONE credential resolution (pasted key wins, keyless fallback on the official endpoint, custom-endpoint and no-login refusals).
|
||||
|
||||
@@ -25,6 +25,66 @@ import Foundation
|
||||
@testable import Museion
|
||||
import Testing
|
||||
|
||||
/// The smallest NSDraggingInfo the drag overrides read: only the
|
||||
/// pasteboard matters (the stock text drop also wants a destination view,
|
||||
/// which the hosted text view supplies itself).
|
||||
@MainActor
|
||||
final class DragInfoStub: NSObject, NSDraggingInfo {
|
||||
let draggingPasteboard: NSPasteboard
|
||||
init(_ pb: NSPasteboard) {
|
||||
draggingPasteboard = pb
|
||||
}
|
||||
|
||||
var draggingDestinationWindow: NSWindow? {
|
||||
nil
|
||||
}
|
||||
|
||||
var draggingSourceOperationMask: NSDragOperation {
|
||||
[.copy]
|
||||
}
|
||||
|
||||
var draggingLocation: NSPoint {
|
||||
.zero
|
||||
}
|
||||
|
||||
var draggedImageLocation: NSPoint {
|
||||
.zero
|
||||
}
|
||||
|
||||
var draggedImage: NSImage? {
|
||||
nil
|
||||
}
|
||||
|
||||
var draggingSource: Any? {
|
||||
nil
|
||||
}
|
||||
|
||||
var draggingSequenceNumber: Int {
|
||||
0
|
||||
}
|
||||
|
||||
func slideDraggedImage(to _: NSPoint) {}
|
||||
override func namesOfPromisedFilesDropped(atDestination _: URL) -> [String]? {
|
||||
nil
|
||||
}
|
||||
|
||||
var draggingFormation: NSDraggingFormation = .none
|
||||
var animatesToDestination = false
|
||||
var numberOfValidItemsForDrop = 0
|
||||
func enumerateDraggingItems(
|
||||
options _: NSDraggingItemEnumerationOptions,
|
||||
for _: NSView?,
|
||||
classes _: [AnyClass],
|
||||
searchOptions _: [NSPasteboard.ReadingOptionKey: Any],
|
||||
using _: @escaping (NSDraggingItem, Int, UnsafeMutablePointer<ObjCBool>) -> Void,
|
||||
) {}
|
||||
var springLoadingHighlight: NSSpringLoadingHighlight {
|
||||
.none
|
||||
}
|
||||
|
||||
func resetSpringLoading() {}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
struct ImageIngestTests {
|
||||
/// Throwaway Home + a saved post standing in for the open editor
|
||||
@@ -96,9 +156,10 @@ struct ImageIngestTests {
|
||||
#expect(!FileManager.default.fileExists(atPath: folder.appendingPathComponent("assets").path))
|
||||
}
|
||||
|
||||
// MARK: - #141 drag-layer entry (ingestDrop — the SwiftUI drop
|
||||
// MARK: - #141 drag-layer entry (ingestDrop — whichever surface took
|
||||
|
||||
// target's perform lands on the text view)
|
||||
// the drag routes here: the text view's own handlers over the editor,
|
||||
// the window SwiftUI destination elsewhere)
|
||||
|
||||
@Test func `ingestDrop copies lands the ref and selects alt`() throws {
|
||||
let (_, folder) = try ingestHome()
|
||||
@@ -129,6 +190,189 @@ struct ImageIngestTests {
|
||||
#expect(try !draft.ingestDrop([imageSource("x.png")]))
|
||||
}
|
||||
|
||||
// MARK: - 27.2 drag routing (a drag goes to the deepest destination:
|
||||
|
||||
// FileDropTextView owns drops that land on the editor — stock NSTextView
|
||||
// handling would paste the file PATH)
|
||||
|
||||
/// A Finder-shaped drag pasteboard: `public.file-url` plus the legacy
|
||||
/// filenames type NSTextView registers for.
|
||||
private func finderDragPasteboard(_ urls: [URL]) -> NSPasteboard {
|
||||
let filenames = NSPasteboard.PasteboardType(rawValue: "NSFilenamesPboardType")
|
||||
let pb = NSPasteboard(name: .drag)
|
||||
pb.declareTypes([.fileURL, filenames], owner: nil)
|
||||
pb.setString(urls[0].absoluteString, forType: .fileURL)
|
||||
pb.setPropertyList(urls.map(\.path), forType: filenames)
|
||||
return pb
|
||||
}
|
||||
|
||||
/// A live text view in a window (the stock text drop inserts only into
|
||||
/// a hosted view). Caller orders the window out.
|
||||
private func hostedView() -> (tv: ProseListTextView, win: NSWindow) {
|
||||
let win = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 200, height: 200), styleMask: [.titled], backing: .buffered, defer: false)
|
||||
let tv = ProseListTextView()
|
||||
tv.string = "Body.\n"
|
||||
win.contentView?.addSubview(tv)
|
||||
win.makeFirstResponder(tv)
|
||||
return (tv, win)
|
||||
}
|
||||
|
||||
/// A temp markdown file standing in for a dragged guest.
|
||||
private func markdownSource() throws -> URL {
|
||||
let md = FileManager.default.temporaryDirectory.appendingPathComponent("imageingest-\(UUID().uuidString).md")
|
||||
try "# Guest\n".write(to: md, atomically: true, encoding: .utf8)
|
||||
return md
|
||||
}
|
||||
|
||||
@Test func `a file drag landing on the text view routes, never pastes the path`() throws {
|
||||
let (_, folder) = try ingestHome()
|
||||
let (tv, win) = hostedView()
|
||||
defer { win.orderOut(nil) }
|
||||
tv.ingestFolder = folder
|
||||
tv.onFileDrop = { [weak tv] in tv?.ingestDrop($0) ?? false } // the gate's router in miniature
|
||||
let source = try imageSource("sketch.png")
|
||||
let drag = DragInfoStub(finderDragPasteboard([source]))
|
||||
|
||||
#expect(tv.draggingEntered(drag) == .copy)
|
||||
#expect(tv.draggingUpdated(drag) == .copy)
|
||||
#expect(tv.performDragOperation(drag))
|
||||
#expect(tv.string.contains(""))
|
||||
#expect(!tv.string.contains(source.path), "the stock path paste survived")
|
||||
|
||||
// Unrouted (no handler mounted): a Finder drag claims nothing and
|
||||
// pastes nothing.
|
||||
let (bare, bareWin) = hostedView()
|
||||
defer { bareWin.orderOut(nil) }
|
||||
let bareDrag = DragInfoStub(finderDragPasteboard([source]))
|
||||
#expect(bare.draggingEntered(bareDrag) == [])
|
||||
#expect(!bare.performDragOperation(bareDrag))
|
||||
#expect(bare.string == "Body.\n")
|
||||
}
|
||||
|
||||
@Test func `a text-only drag keeps the stock drop and never reaches the router`() {
|
||||
let (tv, win) = hostedView()
|
||||
defer { win.orderOut(nil) }
|
||||
var routed: [URL]?
|
||||
tv.onFileDrop = { routed = $0; return true }
|
||||
let pb = NSPasteboard(name: .drag)
|
||||
pb.declareTypes([.string], owner: nil)
|
||||
pb.setString("dropped text", forType: .string)
|
||||
|
||||
#expect(FileDropTextView.classify(pb) == .text)
|
||||
#expect(tv.draggingEntered(DragInfoStub(pb)) == .copy)
|
||||
#expect(tv.performDragOperation(DragInfoStub(pb)))
|
||||
#expect(tv.string.contains("dropped text"))
|
||||
#expect(routed == nil)
|
||||
|
||||
// URL-less AND text-less (raw image data from Photos/Preview): bounces.
|
||||
let png = NSPasteboard(name: .drag)
|
||||
png.declareTypes([.png], owner: nil)
|
||||
#expect(tv.draggingEntered(DragInfoStub(png)) == [])
|
||||
#expect(!tv.performDragOperation(DragInfoStub(png)))
|
||||
#expect(tv.string.contains("dropped text"))
|
||||
}
|
||||
|
||||
@Test func `the drag probe follows the pasteboard contents, not its memory`() throws {
|
||||
let (tv, win) = hostedView()
|
||||
defer { win.orderOut(nil) }
|
||||
let source = try imageSource("sketch.png")
|
||||
let pb = finderDragPasteboard([source])
|
||||
#expect(tv.dropKind(of: pb) == .urls([source]))
|
||||
// Same pasteboard object, new contents (changeCount moved): follows.
|
||||
pb.declareTypes([.string], owner: nil)
|
||||
pb.setString("now text", forType: .string)
|
||||
#expect(tv.dropKind(of: pb) == .text)
|
||||
pb.clearContents()
|
||||
#expect(tv.dropKind(of: pb) == .none)
|
||||
}
|
||||
|
||||
@Test func `the outline rows bounce a file drag instead of pasting the path`() throws {
|
||||
let win = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 200, height: 200), styleMask: [.titled], backing: .buffered, defer: false)
|
||||
defer { win.orderOut(nil) }
|
||||
let row = RowTextView()
|
||||
row.string = "- item"
|
||||
win.contentView?.addSubview(row)
|
||||
let drag = try DragInfoStub(finderDragPasteboard([imageSource("sketch.png")]))
|
||||
|
||||
#expect(row.draggingEntered(drag) == [])
|
||||
#expect(!row.performDragOperation(drag))
|
||||
#expect(row.string == "- item")
|
||||
}
|
||||
|
||||
@Test func `a web URL refuses loudly with the type notice and plants nothing`() throws {
|
||||
// A browser image drag reaches the router as an https URL — the
|
||||
// extension looks publishable, but nothing is on disk to copy. The
|
||||
// sink would refuse it too; only the isFileURL gate names the type.
|
||||
let (_, folder) = try ingestHome()
|
||||
let tv = ProseListTextView()
|
||||
tv.string = "Body.\n"
|
||||
tv.ingestFolder = folder
|
||||
let web = try #require(URL(string: "https://example.com/cat.jpg"))
|
||||
#expect(!tv.ingestDrop([web]))
|
||||
#expect(tv.lastIngestNotice?.hasPrefix("Drop images") == true, "notice: \(tv.lastIngestNotice ?? "nil")")
|
||||
#expect(!FileManager.default.fileExists(atPath: folder.appendingPathComponent("assets").path))
|
||||
}
|
||||
|
||||
@Test func `a file that vanished after the drag refuses as missing, not as a folder`() throws {
|
||||
let (_, folder) = try ingestHome()
|
||||
let tv = ProseListTextView()
|
||||
tv.string = "Body.\n"
|
||||
tv.ingestFolder = folder
|
||||
let gone = try imageSource("ghost.png")
|
||||
try FileManager.default.removeItem(at: gone)
|
||||
#expect(!tv.ingestDrop([gone]))
|
||||
let notice = try #require(tv.lastIngestNotice)
|
||||
#expect(notice.contains("couldn’t be read"), "notice: \(notice)")
|
||||
#expect(!notice.contains("folder"), "notice: \(notice)")
|
||||
#expect(!FileManager.default.fileExists(atPath: folder.appendingPathComponent("assets").path))
|
||||
}
|
||||
|
||||
// MARK: - The one router (AppGateState.routeFileDrop)
|
||||
|
||||
@Test func `the router opens a pure-markdown set as the guest`() throws {
|
||||
let gate = AppGateState()
|
||||
let md = try markdownSource()
|
||||
defer { try? FileManager.default.removeItem(at: md) }
|
||||
#expect(gate.routeFileDrop([md]))
|
||||
#expect(gate.posts.externalSession != nil)
|
||||
}
|
||||
|
||||
@Test func `the router refuses everything while a Cold Turkey block holds`() throws {
|
||||
let gate = AppGateState()
|
||||
gate.posts.newPost()
|
||||
gate.posts.draft?.text = "seed words here"
|
||||
gate.startWritingLock(goal: .words(2))
|
||||
defer {
|
||||
gate.writingLock.feed(text: "seed words here plus two more")
|
||||
gate.writingLock.tick()
|
||||
}
|
||||
let md = try markdownSource()
|
||||
defer { try? FileManager.default.removeItem(at: md) }
|
||||
#expect(gate.writingLock.isLocked)
|
||||
#expect(!gate.routeFileDrop([md]))
|
||||
#expect(gate.posts.externalSession == nil)
|
||||
}
|
||||
|
||||
@Test func `the router hands non-markdown to the open piece's ingest`() throws {
|
||||
let gate = AppGateState()
|
||||
let (_, folder) = try ingestHome()
|
||||
let source = try imageSource("sketch.png")
|
||||
// No editor mounted: bounce.
|
||||
#expect(!gate.routeFileDrop([source]))
|
||||
let tv = ProseListTextView()
|
||||
tv.string = "Body.\n"
|
||||
tv.ingestFolder = folder
|
||||
gate.proseDrop.textView = tv
|
||||
#expect(gate.routeFileDrop([source]))
|
||||
#expect(tv.string.contains(""))
|
||||
// A mixed md+image set reaches the ingest's loud refusal, never the guest.
|
||||
let md = try markdownSource()
|
||||
defer { try? FileManager.default.removeItem(at: md) }
|
||||
#expect(try !gate.routeFileDrop([imageSource("second.png"), md]))
|
||||
#expect(tv.lastIngestNotice?.hasPrefix("Drop images") == true)
|
||||
#expect(gate.posts.externalSession == nil)
|
||||
}
|
||||
|
||||
// MARK: - #141 finish-audit pins
|
||||
|
||||
@Test func `a dropped symlink refuses with nothing planted`() throws {
|
||||
@@ -149,8 +393,8 @@ struct ImageIngestTests {
|
||||
}
|
||||
|
||||
@Test func `a mixed image and markdown set refuses loudly`() throws {
|
||||
// The window destination forwards only PURE-markdown sets (#91);
|
||||
// a mixed set must reach this refusal, not vanish behind the md.
|
||||
// The router forwards only PURE-markdown sets (#91); a mixed set
|
||||
// must reach this refusal, not vanish behind the md.
|
||||
let (_, folder) = try ingestHome()
|
||||
let tv = ProseListTextView()
|
||||
tv.string = "Body.\n"
|
||||
|
||||
@@ -322,7 +322,7 @@ extension ProseFoldRekeyTests {
|
||||
debounce: .seconds(3600),
|
||||
)
|
||||
let coordinator = ProseTextView.Coordinator(
|
||||
representable: ProseTextView(session: session, dropBridge: ProseDropBridge()),
|
||||
representable: ProseTextView(session: session, dropBridge: ProseDropBridge(), routeDrop: { _ in false }),
|
||||
)
|
||||
textView.delegate = coordinator // production wiring (PostEditorView)
|
||||
textView.setSelectedRange(NSRange(location: 0, length: 0))
|
||||
|
||||
Reference in new issue
Block a user