Slate: Copying from Slate adds a newline after first character

Created on 18 Jan 2017  路  5Comments  路  Source: ianstormtaylor/slate

Copying this fragment:

screen shot 2017-01-18 at 10 15 56

...and pasting it here gives:

From Firefox

r
endered block quote in the middle of the page, like this:

    A wise quote.

From Chrome and Safari

r
endered block quote in the middle of the page, like this:
A wise quote.

You can see the unwanted newline after the first character in any case.

bug

Most helpful comment

Putting it on an empty span, or on the first child element node sounds great to me! I'd love a PR that implements that. Thanks!

All 5 comments

I've also seen this in every instance of Slate I have played with, including in my own app.

it's because slate put's the first character of the selection in a span, (used to store the document fragment in the span's attribute, so could later paste exactly that.
simplest way around, if you don't need that functionality is to comment out

var wrapper = window.document.createElement('span');
var text = contents.childNodes[0];
var char = text.textContent.slice(0, 1);
var first = window.document.createTextNode(char);
var rest = text.textContent.slice(1);
text.textContent = rest;
wrapper.appendChild(first);
wrapper.setAttribute('data-slate-fragment', encoded);
contents.insertBefore(wrapper, text)

from core.js plugin onCutOrCopy function, or make the span be around the whole selection

@ianstormtaylor Do you have something in mind to address this already? If not, do you plan to address this issue as a bug?

why not put the data-slate-fragment on an empty span, or on the first childnode?

Putting it on an empty span, or on the first child element node sounds great to me! I'd love a PR that implements that. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AlexeiAndreev picture AlexeiAndreev  路  3Comments

markolofsen picture markolofsen  路  3Comments

vdms picture vdms  路  3Comments

bunterWolf picture bunterWolf  路  3Comments

ianstormtaylor picture ianstormtaylor  路  3Comments