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]: Inserting new block using insertContent function at paragraph start will create empty paragraph above #5943

Closed
1 task done
volarname opened this issue Dec 17, 2024 · 2 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

@volarname
Copy link
Contributor

Affected Packages

core

Version(s)

2.10.3

Bug Description

Steps to reproduce

  1. Open https://codesandbox.io/p/devbox/jovial-waterfall-z9nvpx
  2. Place cursor at paragraph start
  3. use button to insert block node (using tiptap insertContent function)
  4. check printed json output or visually check the spacing of created block
  5. it will create unwanted empty paragraph above

Browser Used

Chrome

Code Example URL

https://codesandbox.io/p/devbox/jovial-waterfall-z9nvpx

Expected Behavior

it should insert new node without creating additional empy paragraph

Additional Context (Optional)

when you now position at the end of paragraph and insert the block node using insertContent function it will do it correctly, it will just insert it after current paragraph, no empty paragraph will appear after, so it should do it same on paragraph start.

Dependency Updates

  • Yes, I've updated all my dependencies.
@volarname volarname 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 Dec 17, 2024
@guanriyue
Copy link
Contributor

This is not a bug. When you place the mouse at the beginning of a paragraph, the cursor is actually positioned at pos=1, not pos=0. Therefore, when you insert a node, the paragraph gets split. Since there's no text before pos=1, the first part of the paragraph becomes an empty paragraph, followed by the node you insert, and then the second part of the original paragraph forms a new paragraph.

I recorded a video to illustrate this. In your example, I changed the first node in the content to content-lock, which is an atom node. By using gapcursor, I was able to place the cursor at pos=0, so when I pressed the button to insert another content-lock, there were no issues. I also demonstrated inserting content-lock at the middle of a paragraph, where the paragraph gets split into two distinct parts.

2025-01-03.19.34.23.mov

@nperez0111
Copy link
Contributor

Agreed, closing

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
None yet
Development

No branches or pull requests

3 participants