From f045b597eab34275126b6810c605bf5746a540c6 Mon Sep 17 00:00:00 2001 From: Ashutosh Rishi Ranjan Date: Tue, 31 Oct 2017 10:12:17 +1100 Subject: [PATCH] [onCutOrCopy] Creating the phony copy div at the same level as the real div (#1350) * Creating the phony copy div at the same level as the real div * Added COMPAT desc for the Firefox scroll jump fix * Update after.js * Update after.js --- packages/slate-react/src/plugins/after.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/slate-react/src/plugins/after.js b/packages/slate-react/src/plugins/after.js index 7c9953f45..fd5b09464 100644 --- a/packages/slate-react/src/plugins/after.js +++ b/packages/slate-react/src/plugins/after.js @@ -233,6 +233,15 @@ function AfterPlugin() { div.setAttribute('contenteditable', true) div.style.position = 'absolute' div.style.left = '-9999px' + + // COMPAT: In Firefox, the viewport jumps to find the phony div, so it + // should be created at the current scroll offset with `style.top`. + // The box model attributes which can interact with 'top' are also reset. + div.style.border = '0px' + div.style.padding = '0px' + div.style.margin = '0px' + div.style.top = `${window.pageYOffset || window.document.documentElement.scrollTop}px` + div.appendChild(contents) body.appendChild(div)