From 56e568d063537c3267f944fd616cc0989fd4f0f0 Mon Sep 17 00:00:00 2001 From: AlbertHilb Date: Sat, 10 Jun 2017 19:47:00 +0200 Subject: [PATCH] When the parameter passed to `isInEditor` is a text node use its parent instead (#857) * When the parameter passed to `isInEditor` is a text node use its parent for the check. * Don't reuse `target` parameter. Add details to the comment. --- src/components/content.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/content.js b/src/components/content.js index 3bc9b530e..854ca16a6 100644 --- a/src/components/content.js +++ b/src/components/content.js @@ -247,9 +247,12 @@ class Content extends React.Component { isInEditor = (target) => { const { element } = this + // COMPAT: Text nodes don't have `isContentEditable` property. So, when + // `target` is a text node use its parent element for check. + const el = target.nodeType === 3 ? target.parentElement : target return ( - (target.isContentEditable) && - (target == element || findClosestNode(target, '[data-slate-editor]') == element) + (el.isContentEditable) && + (el === element || findClosestNode(el, '[data-slate-editor]') === element) ) }