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 nothing if the requested content already exists at the position #4291

Open
1 of 2 tasks
Nantris opened this issue Aug 5, 2023 · 3 comments
Open
1 of 2 tasks
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 5, 2023

Which packages did you experience the bug in?

core

What Tiptap version are you using?

2.1.0-rc.12

What’s the bug you are facing?

I'd expect that insertContent('<p></p>') inside of an empty paragraph would result in another paragraph, but instead it does nothing. This indeterminacy makes building more complex commands difficult because you can't rely on insertContent to do the same thing under all circumstances.

What browser are you using?

Chrome

Code example

No response

What did you expect to happen?

insertContent('<p></p>') inside of an empty paragraph should insert another empty paragraph.

Anything to add? (optional)

No response

Did you update your dependencies?

  • Yes, I’ve updated my dependencies to use the latest version of all packages.

Are you sponsoring us?

  • Yes, I’m a sponsor. 💖
@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 5, 2023
@Nantris
Copy link
Contributor Author

Nantris commented Aug 5, 2023

This is debatably already the correct behavior. It can be worked around by using insertContentAt instead to target a bounding position rather than a text position. I think it's a little wonky though.

@bdbch
Copy link
Contributor

bdbch commented Aug 6, 2023

I'm not sure about that – I guess the reason why nothing happens is because the Prosemirror schema will disallow a paragraph inside a paragraph and will just not insert it?

When would you add a new node and when would you just disallow adding content?

@Nantris
Copy link
Contributor Author

Nantris commented Aug 6, 2023

It seems perhaps like that's not the cause. My rationale is that I've found if you have any content in the paragraph then invoking insertContent('<p></p>') inserts the expected paragraph. It only has this issue on completely empty paragraphs.

It's almost like it thinks it's already inserted the paragraph because it already finds one there. With that in mind, I don't know that there's any time that insertion should be disallowed. I'm not really sure what the cause is though.

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: Triage open
Development

No branches or pull requests

3 participants