Pasting white space sometimes lead to Exceptions

I’m seeing an issue which I manage to reproduce also on the example editor at prosemirror.net : I have a single plain text space in the clipboard (e.g. copied from the console) and when I paste it in the editor, I see a RangeError: Empty text nodes are not allowed in the console. My app crashes so it’s a bit of a bummer though.

I’ve used a debugger and narrowed it down to parseFromClipboard, this snippet:

text.trim().split(/(?:\r\n?|\n)+/).forEach(function (block) {
        dom.appendChild(document.createElement("p")).appendChild(serializer.serializeNode(schema.text(block, marks)));
      });

when block is the empty string "". Shouldn’t there be a check for this, so that there’s no child appended there in this case?

To clarify, text is " ".

Good point. This patch should help with that.

That indeed fixes the exception but in the end the whitespace isn’t pasted in at all. Not sure how relevant this is but it feels a bit off.

The whitespace trimming seems to have been added as an afterthought at some point. I agree it doesn’t seem like a good idea. Added a patch that removes it.

Thanks, if you tag a release I’ll give it another try.

On a possibly related note, I’m using transformPasted to look for link-line things inside text. I’m especially interested in paragraphs that only contain a single link inside, as those can be possibly be expanded via oembed.

I’ve noticed that when I paste multiple paragraphs, transformPasted is called multiple times, one per time with one fragment per paragrph. Is that by design? Could it be documented? If it’s the case then my check is quite simply for childCount === 1 and the first child is a text node with a link mark on it…

That’s weird—it’s called exactly once, with the full slice, at the bottom of parseFromClipboard.

ohh never mind again, the code I copied was recursive :slight_smile: the transformPasted is indeed edited only once.