-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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]: selectAll
causes an unexpected newline when pasting
#6165
Comments
I don't think this is a bug. When selecting all content, what you're actually selecting is the Paragraph itself, not just the text content of the Paragraph. When pasting, the content being pasted is also a Paragraph node, and clearly, a Paragraph node cannot nest inside another Paragraph node. Therefore, a new Paragraph node will be inserted at current position. |
I understand what you mean about it not being a bug. |
You can use The following solution is an example that utilizes If I have time later, I will try to provide a CodeSandbox. import { Extension } from '@tiptap/core';
import { Slice } from '@tiptap/pm/model';
import { Plugin } from '@tiptap/pm/state';
export const PasteParagraph = Extension.create({
name: 'pasteParagraph',
addProseMirrorPlugins() {
return [
new Plugin({
props: {
transformPasted: slice => {
const content = slice.content;
const isSingleParagraph =
content.childCount === 1 &&
content.firstChild?.type.name === 'paragraph';
if (isSingleParagraph) {
return new Slice(content, 1, 1);
}
return slice;
},
},
}),
];
},
}); |
Thank you for being kind enough to attach the code. I will try to create the desired requirement using the method you mentioned. |
Affected Packages
core
Version(s)
2.11.0
Bug Description
When using the selectAll command and pasting content, an unexpected newline is inserted. This seems to be caused by the selectAll implementation, which sets the selection to AllSelection but does not handle the paste behavior properly.
Steps to Reproduce:
editor.commands.selectAll()
.2025-03-07.17.00.58.mov
Browser Used
Chrome
Code Example URL
No response
Expected Behavior
The pasted content should replace the selection without inserting an extra newline.
2025-03-07.17.02.54.mov
Additional Context (Optional)
The issue might stem from how AllSelection interacts with the transaction when pasting. It could be necessary to handle paste events explicitly or adjust the selection behavior.
This looks like an issue with the merged PRs and issues below.
#5900
#5516
Dependency Updates
The text was updated successfully, but these errors were encountered: