From 6aba4260f84a4ffe6ccbe60078c95f7c39a8a6c0 Mon Sep 17 00:00:00 2001 From: lakatosandrei Date: Mon, 19 Aug 2019 19:08:22 +0300 Subject: [PATCH] fix(firefox): fixed the bug that happens when changing the focus from one field to another (#2236) * fix(firefox): fixed the bug that happens when changing the focus from one field to another * Publish - slate-base64-serializer@0.2.69 - slate-html-serializer@0.7.8 - slate-hyperscript@0.10.8 - slate-plain-serializer@0.6.8 - slate-prop-types@0.4.67 - slate-react@0.18.11 - slate-simulator@0.4.67 - slate@0.41.3 * Publish - slate-base64-serializer@0.2.70 - slate-html-serializer@0.7.9 - slate-hyperscript@0.10.9 - slate-plain-serializer@0.6.9 - slate-prop-types@0.4.68 - slate-react@0.18.12 - slate-simulator@0.4.68 - slate@0.41.4 * Publish - slate-react@0.18.13 * Revert "Fix an occasional crash in Firefox in isInEditor (#2229)" This reverts commit 1ff050265bbcb8e6d5b5bbf9dc8839f1c6a2ddef. * fix(firefox): added postinstall script to the main project * fix(firefox): removed error causing line * fix(firefox): added the right fix for this * fix(firefox): added the best fix for this * fix(firefox): made the range a constant * fix(firefox): added the removeAllRanges inside the if wrapper * fix(lint): fixed lint error * fix(versions): removed changes for the package.json files * fix(versions): removed remaining changes for the package.json files * fix(conflict): fixed the issue that resolving the conflicts caused last time * fix(lint): fixed the last lint error * chore(content): moved comment in setTimeout to see why git is not showing conflicts locally --- .../slate-react/src/components/content.js | 58 ++++++++----------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/packages/slate-react/src/components/content.js b/packages/slate-react/src/components/content.js index 426a94243..8c2a5801a 100644 --- a/packages/slate-react/src/components/content.js +++ b/packages/slate-react/src/components/content.js @@ -286,43 +286,39 @@ class Content extends React.Component { // Otherwise, set the `isUpdatingSelection` flag and update the selection. updated = true this.tmp.isUpdatingSelection = true - removeAllRanges(native) - // COMPAT: IE 11 does not support `setBaseAndExtent`. (2018/11/07) - if (native.setBaseAndExtent) { - // COMPAT: Since the DOM range has no concept of backwards/forwards - // we need to check and do the right thing here. - if (isBackward) { - native.setBaseAndExtent( - range.endContainer, - range.endOffset, - range.startContainer, - range.startOffset - ) + if (!IS_FIREFOX) { + removeAllRanges(native) + + // COMPAT: IE 11 does not support `setBaseAndExtent`. (2018/11/07) + if (native.setBaseAndExtent) { + // COMPAT: Since the DOM range has no concept of backwards/forwards + // we need to check and do the right thing here. + if (isBackward) { + native.setBaseAndExtent( + range.endContainer, + range.endOffset, + range.startContainer, + range.startOffset + ) + } else { + native.setBaseAndExtent( + range.startContainer, + range.startOffset, + range.endContainer, + range.endOffset + ) + } } else { - native.setBaseAndExtent( - range.startContainer, - range.startOffset, - range.endContainer, - range.endOffset - ) + native.addRange(range) } - } else { - native.addRange(range) } // Scroll to the selection, in case it's out of view. scrollToSelection(native) - // Then unset the `isUpdatingSelection` flag after a delay, to ensure that - // it is still set when selection-related events from updating it fire. + // Then unset the `isUpdatingSelection` flag after a delay. setTimeout(() => { - // COMPAT: In Firefox, it's not enough to create a range, you also need - // to focus the contenteditable element too. (2016/11/16) - if (IS_FIREFOX && this.ref.current) { - this.ref.current.focus() - } - this.tmp.isUpdatingSelection = false debug.update('updateSelection:setTimeout', { @@ -357,12 +353,6 @@ class Content extends React.Component { let el try { - // COMPAT: In Firefox, sometimes the node can be comment which doesn't - // have .closest and it crashes. - if (target.nodeType === 8) { - return false - } - // COMPAT: Text nodes don't have `isContentEditable` property. So, when // `target` is a text node use its parent node for check. el = target.nodeType === 3 ? target.parentNode : target