-
-
Notifications
You must be signed in to change notification settings - Fork 461
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
fix: pasting in table #1181
fix: pasting in table #1181
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Hey @YousefED, i did find anything paste into block will actually create a new block(another line), this seems a default action. I did test both plaintext and html text from clipboard, it all go straight to another line. This seems against common user behaviour. For example, if you selection in one of the block after a word, if you paste some plain text, it still create another block after current block instead of append current text selection. I'm not sure if BlockNote suppose to do past like this, but if not this could still be a problem for pasting. I can see this fix apply table so it wont able to break table anymore. It might be take care more action if it is a plain text and selection in a block it need to be append. this can be done in paste plugin in paste() call to identify the clipboard source as well. Recording: |
for what i mentioned below, you can add this part code to fix to avoid auto create new block/lines
paste(_view, event) {
// rest code in past()
// if (format === "text/html") {
// ...other code
// }
if (format === "text/plain") {
editor._tiptapEditor.view.pasteHTML(data);
return true;
}
// this is existed code
editor._tiptapEditor.view.pasteText(data);
return true
} this should fix some other paste issue as well :) |
That would break pasting bold / italic / links / etc right?
…On Fri, 25 Oct 2024 at 15:47, Michael Wonng ***@***.***> wrote:
for what i mentioned below, you can add this part code to fix to avoid
auto create new block/lines
packages/core/src/api/clipboard/fromClipboard/pasteExtension.ts
// if (format === "text/html") {
// ...other code
// }
if (format === "text/plain") {
editor._tiptapEditor.view.pasteHTML(data);
return true;
}
editor._tiptapEditor.view.pasteText(data);
—
Reply to this email directly, view it on GitHub
<#1181 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC2BWPYLLV5LL3S7CZVGHTZ5JDY5AVCNFSM6AAAAABQQ4YZMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMZXHAZTAMZSGE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
for now, if you paste anything plain text, it will default insert another block and break current block into 2 blocks,
in this case, if i paste any thing, it will become
I'm not sure is this intend or not, but if it is not, you can add this part code if (format === "text/plain") {
editor._tiptapEditor.view.pasteHTML(data);
return true;
} to make paste as inline paste (which i think more nature) update: try to copy something plain text only. |
maybe i need some more clarify sorry for confusion. the screenshost show one with HTML(with style, so when you copy plain text and paste into BlockNote, it will actually break lines. This is not related to table specifically, your code should already fix paste inside table, but it act as default for some scenario(break the block), but i think my suggestion code can be in another PR for pasting as well |
I think this paste issue might be more than it is, i also met this issue in my previous job. so I will try to list as possbile. Paste into table is simple but the content in clipboard might be various, it could be:
Those all rich text, but for different reason it might be act as different behaviour. e.g inline rich text mostly work well with the fix only parseHTML. but for others and possible some other scenarios i didnt mentioned, it still able to break the block(including table), and at the same time it still need to think about if we need to default paste content into a new block and when. In my previous work we do actually parse clipboard and reformate to another slice and dispatch the transaction.(it more than 700 lines code ONLY in Just FYI. |
InvestigationUPDATE: video and explaination: https://www.loom.com/share/e0c9533be0e44d338d3bb96d7cd6cf6c after i have a lot of test, i think i fount the issue, it might be a little complex to explain and these might need to related to some feature if BlockNote able to support: The core it need to be think about:
When you copy something, the HTML node will be parse into editor node, when it recongnise as a inline node, it will be paste properly, such as copy of a span, or part of paragph. When you copy something HTML it could be parse into a block. e.g. heading, list, etc, it will be parse into a Editor node directly. As i tested, when your clipboard has HTML and it will able to be parse into a block, it will break the current block into two. otherwise it will keep the block and do a inline paste. For this change you can still see if you copied a heading HTML into table cell, e.g. This clipboard in
This clipboard in
Example:Copy this word not break.
Warning If triple click to copy whole line, paste will also break . this heading will break
What should do about paste?It need to be consider when pasting:
Sorry i write a lot of stuff here, i understand paste is pretty trick part of editor and it also act different in Chrome and FireFox when copy the samething. It still need to be consider if BlockNote want a better user expeirence. Back to this case, I would say, maybe treat all paste in table as a plain text might be the better option for now. |
fixes this issue:
Kapture.2024-10-21.at.12.14.32.mp4
I also tried to fix #1077 at the same time, (this happens when trying to paste HTML content that's more than a single element, but this is quite a bit more involved unfortunately,