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

Inserting a block node as first node marks it as selected (adding nodes afterwards deletes the block node) #3355

Open
1 of 2 tasks
mejo- opened this issue Oct 25, 2022 · 6 comments
Labels
Type: Bug The issue or pullrequest is related to a bug

Comments

@mejo-
Copy link
Contributor

mejo- commented Oct 25, 2022

What’s the bug you are facing?

When inserting a block node as first node into an empty editor using `insertContent(), the inserted node is marked as selected (focused) afterwards. The result is that insertions happening directly after the first one overwrite the content of the first one.

Interestingly, this only happens on empty content. As soon as the editor has some content, the bug is no longer reproducible.

I tested this with block nodes of type horizontalRule and image.

Which browser was this experienced in? Are any special extensions installed?

Latest Firefox and Chromium.

How can we reproduce the bug on our side?

Doing the following on editor with empty content will insert a horizontal line, mark it as selected and overwrite it with the text 'abc' afterwards:

this.editor = new Editor({ extensions: [ StarterKit ] });
this.editor.chain().insertContent({ type: 'horizontalRule' }).insertContent("abc").focus().run();

Can you provide a CodeSandbox?

https://codesandbox.io/s/tiptap-block-node-bug-1cetce?file=/src/App.vue

What did you expect to happen?

The second insertContent() should append content after the first one instead of replacing it.

Anything to add? (optional)

Seems like tr.replaceWith() in insertContentAt() results in the new content being marked as selected in some cases.

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. 💖
@mejo- mejo- added the Type: Bug The issue or pullrequest is related to a bug label Oct 25, 2022
mejo- added a commit to nextcloud/text that referenced this issue Oct 27, 2022
Tiptap `setImage()` marks the added image as selected in some cases
(especially when added as first element in the document), which leads to
the image being overwritten by subsequent `insertContent()` command.

See ueberdosis/tiptap#3355 for the relevant
upstream bug.

Mitigate this bug by explicitly changing selection to the end of the
current text block (`selectTextblockEnd()`)  in command chain between
adding the image and the line break.

Signed-off-by: Jonas <jonas@freesources.org>
@mejo-
Copy link
Contributor Author

mejo- commented Oct 27, 2022

It's possible to workaround this bug by adding selectTextblockEnd() in the command chain after the first insertContent(). E.g.:

this.editor.chain().insertContent({ type: 'horizontalRule' }).selectTextblockEnd().insertContent("abc").focus().run();

@mejo- mejo- changed the title Inserting an block node as first node marks it as selected (adding nodes afterwards deletes the block node) Inserting a block node as first node marks it as selected (adding nodes afterwards deletes the block node) Oct 31, 2022
mejo- added a commit to nextcloud/text that referenced this issue Oct 31, 2022
Tiptap `setImage()` marks the added image as selected when added as
first element in the document), which leads to the image being
overwritten by subsequent `insertContent()` command.

See ueberdosis/tiptap#3355 for the relevant
upstream bug.

Mitigate this bug by explicitly placing the cursor at the end of the
selection between adding the image and the line break.

Signed-off-by: Jonas <jonas@freesources.org>
mejo- added a commit to nextcloud/text that referenced this issue Oct 31, 2022
Tiptap `setImage()` marks the added image as selected when added as
first element in the document), which leads to the image being
overwritten by subsequent `insertContent()` command.

See ueberdosis/tiptap#3355 for the relevant
upstream bug.

Mitigate this bug by explicitly placing the cursor at the end of the
selection between adding the image and the line break.

Signed-off-by: Jonas <jonas@freesources.org>
@mejo-
Copy link
Contributor Author

mejo- commented Oct 31, 2022

Well, turned out that selectTextblockEnd() didn't work as expected. What works though, is placing the cursor to the end of selection in case there's a non-empty selection range after adding the content:

this.editor.commands.insertContent({ type: 'horizontalRule' })
if (!this.editor.view.state.selection.empty) {
    this.editor.chain().focus(this.editor.view.state.selection.to).insertContent("abc").focus().run()
}

mejo- added a commit to nextcloud/text that referenced this issue Nov 8, 2022
Tiptap `setImage()` marks the added image as selected when added as
first element in the document), which leads to the image being
overwritten by subsequent `insertContent()` command.

See ueberdosis/tiptap#3355 for the relevant
upstream bug.

Mitigate this bug by explicitly placing the cursor at the end of the
selection between adding the image and the line break.

Signed-off-by: Jonas <jonas@freesources.org>
max-nextcloud pushed a commit to nextcloud/text that referenced this issue Nov 14, 2022
Tiptap `setImage()` marks the added image as selected when added as
first element in the document), which leads to the image being
overwritten by subsequent `insertContent()` command.

See ueberdosis/tiptap#3355 for the relevant
upstream bug.

Mitigate this bug by explicitly placing the cursor at the end of the
selection between adding the image and the line break.

Signed-off-by: Jonas <jonas@freesources.org>
max-nextcloud pushed a commit to nextcloud/text that referenced this issue Nov 15, 2022
Tiptap `setImage()` marks the added image as selected when added as
first element in the document), which leads to the image being
overwritten by subsequent `insertContent()` command.

See ueberdosis/tiptap#3355 for the relevant
upstream bug.

Mitigate this bug by explicitly placing the cursor at the end of the
selection between adding the image and the line break.

Signed-off-by: Jonas <jonas@freesources.org>
backportbot-nextcloud bot pushed a commit to nextcloud/text that referenced this issue Nov 15, 2022
Tiptap `setImage()` marks the added image as selected when added as
first element in the document), which leads to the image being
overwritten by subsequent `insertContent()` command.

See ueberdosis/tiptap#3355 for the relevant
upstream bug.

Mitigate this bug by explicitly placing the cursor at the end of the
selection between adding the image and the line break.

Signed-off-by: Jonas <jonas@freesources.org>
mejo- added a commit to nextcloud/text that referenced this issue Nov 15, 2022
Tiptap `setImage()` marks the added image as selected when added as
first element in the document), which leads to the image being
overwritten by subsequent `insertContent()` command.

See ueberdosis/tiptap#3355 for the relevant
upstream bug.

Mitigate this bug by explicitly placing the cursor at the end of the
selection between adding the image and the line break.

Signed-off-by: Jonas <jonas@freesources.org>
mejo- added a commit to nextcloud/text that referenced this issue Nov 15, 2022
Tiptap `setImage()` marks the added image as selected when added as
first element in the document), which leads to the image being
overwritten by subsequent `insertContent()` command.

See ueberdosis/tiptap#3355 for the relevant
upstream bug.

Mitigate this bug by explicitly placing the cursor at the end of the
selection between adding the image and the line break.

Signed-off-by: Jonas <jonas@freesources.org>
mejo- added a commit to nextcloud/text that referenced this issue Nov 15, 2022
Tiptap `setImage()` marks the added image as selected when added as
first element in the document), which leads to the image being
overwritten by subsequent `insertContent()` command.

See ueberdosis/tiptap#3355 for the relevant
upstream bug.

Mitigate this bug by explicitly placing the cursor at the end of the
selection between adding the image and the line break.

Signed-off-by: Jonas <jonas@freesources.org>
@github-actions
Copy link
Contributor

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the Info: Stale The issue or pullrequest has not been updated in a while and might be stale label Jan 30, 2023
@mejo-
Copy link
Contributor Author

mejo- commented Jan 30, 2023

The issue unfortunately still exists.

@github-actions github-actions bot removed the Info: Stale The issue or pullrequest has not been updated in a while and might be stale label Jan 31, 2023
@github-actions
Copy link
Contributor

github-actions bot commented May 2, 2023

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the Info: Stale The issue or pullrequest has not been updated in a while and might be stale label May 2, 2023
@mejo-
Copy link
Contributor Author

mejo- commented May 2, 2023

Unfortunately this issue still exists. I fixed the codesandbox example (missing dependency on @tiptap/pm).

@github-actions github-actions bot removed the Info: Stale The issue or pullrequest has not been updated in a while and might be stale label May 3, 2023
@bdbch bdbch added this to Tiptap Aug 4, 2023
@github-project-automation github-project-automation bot moved this to Triage open in Tiptap Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug The issue or pullrequest is related to a bug
Projects
No open projects
Status: Triage open
Development

No branches or pull requests

1 participant