Skip to content

Cut+paste an embedded image loses the id, then breaks permanently #163

Description

@jshirley

(I think there is some overlap with #57 but I am very new to this package so may just be 100% wrong!)

I'm building an opinionated desktop app to track development logs, and using SwiftMarkdownEngine for the content. A big part of the workflow is tracking screenshots/recordings. When I add an image, I get the expected ![[simulator_screenshot_51AB8961-73FD-46B4-A50F-0A285146BF90.png]] text and it previews correctly. If I move that to a different part in the document, the UUID doesn't get carried along with it and the embed breaks permanently.

I leaned on Claude to get a minimal repro, but I think it's accurate:

import SwiftUI
import MarkdownEngine

private let fixedID = UUID(uuidString: "11111111-1111-1111-1111-111111111111")!

struct ReproImageProvider: EmbeddedImageProvider {
    func image(for reference: EmbeddedImageRequest) -> NSImage? {
        guard reference.id == fixedID.uuidString else { return nil }
        let image = NSImage(size: NSSize(width: 40, height: 40))
        image.lockFocus()
        NSColor.systemRed.setFill()
        NSRect(x: 0, y: 0, width: 40, height: 40).fill()
        image.unlockFocus()
        return image
    }
    func fingerprint() -> AnyHashable { 0 }
}

struct ReproView: View {
    @State private var text = "![[photo|\(fixedID.uuidString)]]\n\nSome other paragraph."

    var body: some View {
        NativeTextViewWrapper(
            text: $text,
            configuration: .init(services: .init(images: ReproImageProvider())),
            documentId: "repro"
        )
    }
}
  1. Run ReproView. The red square should render in place of ![[photo|11111111-...]].
  2. Select the entire line containing the embed and press Cmd+X to cut.
  3. After "Some other paragraph." paste (Cmd+V)

Now instead of a red square, should render ![[photo|11111...]] rather than the red square and it can't resolve to a matching id anymore.

Happy to help more with a bit of guidance and confirmation!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions