From 375573f9ee5b355bc92cfc96af5259d95324f8bb Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Thu, 21 Sep 2017 11:55:22 -0700 Subject: [PATCH] fix copying text with leading/trailing white space, fixes #1153 (#1157) * fix copying text with leading/trailing white space, fixes #1153 * remove extra removeChild --- packages/slate-react/src/plugins/core.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/slate-react/src/plugins/core.js b/packages/slate-react/src/plugins/core.js index 846f6fd98..b8ba7b893 100644 --- a/packages/slate-react/src/plugins/core.js +++ b/packages/slate-react/src/plugins/core.js @@ -204,6 +204,11 @@ function Plugin(options = {}) { // node, wrap it in a `` so we have something to set an attribute on. if (attach.nodeType == 3) { const span = window.document.createElement('span') + + // COMPAT: In Chrome and Safari, if we don't add the `white-space` style + // then leading and trailing spaces will be ignored. (2017/09/21) + span.style.whiteSpace = 'pre' + span.appendChild(attach) contents.appendChild(span) attach = span