From 662f584d4daa1375bd144a380c177a677f4d469a Mon Sep 17 00:00:00 2001 From: Sunny Hirai Date: Wed, 24 Apr 2019 17:27:50 -0700 Subject: [PATCH] Support decorations without path (#2697) * Add support with warning for decorations without paths * Fix linting * Update text.js * Update text.js --- packages/slate-react/src/components/text.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/slate-react/src/components/text.js b/packages/slate-react/src/components/text.js index 1d92c63a7..66d81d32e 100644 --- a/packages/slate-react/src/components/text.js +++ b/packages/slate-react/src/components/text.js @@ -1,11 +1,10 @@ import Debug from 'debug' import ImmutableTypes from 'react-immutable-proptypes' +import Leaf from './leaf' +import { PathUtils } from 'slate' import React from 'react' import SlateTypes from 'slate-prop-types' import Types from 'prop-types' -import { PathUtils } from 'slate' - -import Leaf from './leaf' /** * Debug. @@ -117,12 +116,15 @@ class Text extends React.Component { // Otherwise, if the decoration is in a single node, it's not ours. if (start.key === end.key) return false - // If the node's path is before the start path, ignore it. const path = document.assertPath(key) - if (PathUtils.compare(path, start.path) === -1) return false + const startPath = start.path || document.assertPath(start.key) + const endPath = end.path || document.assertPath(end.key) + + // If the node's path is before the start path, ignore it. + if (PathUtils.compare(path, startPath) === -1) return false // If the node's path is after the end path, ignore it. - if (PathUtils.compare(path, end.path) === 1) return false + if (PathUtils.compare(path, endPath) === 1) return false // Otherwise, include it. return true