Skip to content

Paste in code block don't work properly #1594

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

Open
1 task
jdauphant-dinum opened this issue Apr 7, 2025 · 2 comments
Open
1 task

Paste in code block don't work properly #1594

jdauphant-dinum opened this issue Apr 7, 2025 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@jdauphant-dinum
Copy link

Describe the bug
I copy a code, I create a code block, I paste : only the first line is in the code block, the rest is outside the code block.

To Reproduce

  • copy a code (with ``` and enter)
  • create a code block
  • paste into the code block
Bug.TypeCell.mp4

I have tested on the website and on docs.numerique.gouv.fr .

Misc

  • Node version:
  • Package manager:
  • Browser: Brave Version 1.77.95 Chromium: 135.0.7049.52 (Official Build) (arm64) / Firefox 137.0 (aarch64)
  • I'm a sponsor and would appreciate if you could look into this sooner than later 💖
@jdauphant-dinum jdauphant-dinum added the bug Something isn't working label Apr 7, 2025
@mxthxngx
Copy link

mxthxngx commented Apr 28, 2025

Any update on this? @jdauphant-dinum Facing the same issue! Is there any workaround for now? (Absolutely love the product btw)

@mxthxngx
Copy link

mxthxngx commented Apr 29, 2025

Just a heads-up for anyone facing similar issues — I found a workaround for pasting code by implementing a custom pasteHandler.

In my case, the clipboard content wasn’t being detected as "text/markdown", so I switched to checking for "text/plain" instead. Everything else remains the same and works as expected. If "text/markdown" works for you, feel free to adjust the condition.

Here’s the snippet:

   pasteHandler: ({ event, editor, defaultPasteHandler }) => {
                    if (event.clipboardData?.types.includes("text/plain")) {
                        (async () => {
                            const cursor = editor.getTextCursorPosition();
                            console.log("Cursor", cursor.block.type);
                            let data = await navigator.clipboard.readText();

                            if (cursor.block.type === "codeBlock") {
                                data = `\`\`\`\n${data}\n\`\`\``;
                            }
                            const markdownTextBlock = await editor.tryParseMarkdownToBlocks(
                                data
                            );
                            editor.insertBlocks(markdownTextBlock, cursor.block);
                            editor.removeBlocks([cursor.block]);
                        })();
                        return true;
                    }
                    return defaultPasteHandler();
                },

Hope this helps!

@nperez0111 nperez0111 self-assigned this Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants