Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: insertContent does not preserve marks on inserted TextNodes #5540

Closed
1 task done
Nantris opened this issue Aug 23, 2024 · 3 comments
Closed
1 task done

[Bug]: insertContent does not preserve marks on inserted TextNodes #5540

Nantris opened this issue Aug 23, 2024 · 3 comments
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug

Comments

@Nantris
Copy link
Contributor

Nantris commented Aug 23, 2024

Affected Packages

core

Version(s)

2.5.6

Bug Description

We're trying to slice part of the document and re-insert it to preserve marks but I find insertContent loses those marks.

Browser Used

Chrome

Code Example URL

No response

Expected Behavior

Inserted ProseMirror nodes preserve marks as is currently possible when feeding insertContent an HTML string.

Additional Context (Optional)

This occurs whether you try to insert one node or multiple nodes.

Dependency Updates

  • Yes, I've updated all my dependencies.
@Nantris Nantris added Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug labels Aug 23, 2024
@Nantris
Copy link
Contributor Author

Nantris commented Aug 23, 2024

Example of input:
image

In these cases createNodeFromContent returns an empty array.

I'm starting to think I have an incorrect expectation about the command's capabilities. In any event I can presumably handle this at the ProseMirror level, but it would be nice if it could be done with a single call to insertContent.

@nperez0111
Copy link
Contributor

insertContent is for HTML or JSON content not Prosemirror nodes. This is reflected in its types. I do not think we should be adding prosemirror nodes because if they are generated from another schema they will not be valid in this schema. This leads to complexity that makes it easy to do the wrong thing.

Literally all you would need to do is to do Fragment.from(contentYouAreInserting).toJSON() and insertContent with that.

@nperez0111 nperez0111 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 23, 2024
@Nantris
Copy link
Contributor Author

Nantris commented Aug 23, 2024

Fragment.from(contentYouAreInserting).toJSON()

Ended up just doing a .command(({tr}) => tr.insert(...)} but that's nifty! Thanks for the tip!

Studying the underlying types might indeed have made it more clear, but in the IDE it just says it accepts, value: Content which isn't super clear on the surface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug
Projects
Status: Done
Development

No branches or pull requests

2 participants