ProseMirror / prosemirror

The ProseMirror WYSIWYM editor
http://prosemirror.net/
MIT License
7.53k stars 334 forks source link

Clipboard copy text issue #1438

Closed amk221 closed 6 months ago

amk221 commented 6 months ago

I have some tests that checks the text that is copied to the clipboard is correct. After upgrading prosemirror-model to 1.19.4, they started to fail.

This is the text being copied:

Click for actual test document ```js { type: 'doc', content: [ // A normal block { type: 'text_block', content: [ { type: 'text', text: 'Line 1' } ] }, // A block with a blank space in it { type: 'text_block', content: [ { type: 'text', text: ' ' } ] }, // A completely empty block { type: 'text_block' }, // A normal block { type: 'text_block', content: [ { type: 'text', text: 'Line 4' } ] } ] } ```
Line 1

Line 4

And this is the expected result

Line 1

Line 4

The actual result is now:

Line 1

Line 4

I think this is happening because of this:

https://github.com/ProseMirror/prosemirror-model/commit/49db562e89b81984c3b2b9e13d5756b18ef1927c

Which makes sure block separtors are included in textBetween

But the default clipboard text serializer has \n\n as its blockSeparator argument

https://github.com/ProseMirror/prosemirror-view/blob/39fb7c2e71287d6ac2013f5a8c878873a074244e/src/clipboard.ts#L37

Which leads to doubling up

marijnh commented 6 months ago

This is an intended change. You're pasting three blocks, which the text serializer separates by double newlines.

amk221 commented 6 months ago

I’m not pasting I’m copying, 4 blocks not 3

marijnh commented 6 months ago

I know you're copying. I see 3 blocks in your start document.

rmschindler commented 6 months ago

am I understanding correctly, that the issue is that if you copy

Line 1

Line 4

and paste it, it becomes

Line 1

Line 4

?

amk221 commented 6 months ago

Right, I think I understand what's happening:

Because p tags (a block element) tend to come with inherant space around them in browsers, Prosemirror has decided to use \n\n to replicate this space.

But, in my schema, I'm using div, which don't have inherant space around them. And so, it's up to me to chose a different blockSeparator.