From 3e573453a8c5d92963d3f290fb7266f66e2a6b78 Mon Sep 17 00:00:00 2001 From: Victor Pontis Date: Tue, 11 Apr 2017 21:37:08 -0700 Subject: [PATCH] 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 --- src/plugins/core.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/plugins/core.js b/src/plugins/core.js index e0b51198b..fe6e6d269 100644 --- a/src/plugins/core.js +++ b/src/plugins/core.js @@ -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')