1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-27 17:09:53 +02:00

Revert "Remove space after first char when copying from Slate (#716)" (#736)

This reverts commit 3e573453a8.
This commit is contained in:
Per-Kristian Nordnes
2017-04-20 03:36:16 +02:00
committed by Ian Storm Taylor
parent 1421f28f87
commit 7d0f7d0069

View File

@@ -261,11 +261,17 @@ function Plugin(options = {}) {
const zws = [].slice.call(contents.querySelectorAll('[data-slate-zero-width]'))
zws.forEach(zw => zw.parentNode.removeChild(zw))
// Insert an empty span that has the encoded fragment attached as an attribute.
const dataContainer = window.document.createElement('span')
// Wrap the first character of the selection in a span that has the encoded
// fragment attached as an attribute, so it will show up in the copied HTML.
const wrapper = window.document.createElement('span')
const text = contents.childNodes[0]
dataContainer.setAttribute('data-slate-fragment', encoded)
contents.insertBefore(dataContainer, text)
const char = text.textContent.slice(0, 1)
const first = window.document.createTextNode(char)
const rest = text.textContent.slice(1)
text.textContent = rest
wrapper.appendChild(first)
wrapper.setAttribute('data-slate-fragment', encoded)
contents.insertBefore(wrapper, text)
// Add the phony content to the DOM, and select it, so it will be copied.
const body = window.document.querySelector('body')