mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-03-12 09:19:48 +01:00
Remove space after first char when copying from Slate (#716)
Right now if you copy "This thing" from Slate and paste into a plain text app you will get "T his thing" because Slate is making the first character a data holding span. This diff makes the data containing span empty to eliminate this extra space. Closes #562
This commit is contained in:
parent
5c7e31b332
commit
3e573453a8
@ -261,17 +261,11 @@ function Plugin(options = {}) {
|
||||
const zws = [].slice.call(contents.querySelectorAll('[data-slate-zero-width]'))
|
||||
zws.forEach(zw => zw.parentNode.removeChild(zw))
|
||||
|
||||
// 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')
|
||||
// Insert an empty span that has the encoded fragment attached as an attribute.
|
||||
const dataContainer = window.document.createElement('span')
|
||||
const text = contents.childNodes[0]
|
||||
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)
|
||||
dataContainer.setAttribute('data-slate-fragment', encoded)
|
||||
contents.insertBefore(dataContainer, text)
|
||||
|
||||
// Add the phony content to the DOM, and select it, so it will be copied.
|
||||
const body = window.document.querySelector('body')
|
||||
|
Loading…
x
Reference in New Issue
Block a user