From 836ab1d49429cba5b6e9cb0be8baf151c74ffaa2 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 6 Nov 2018 14:01:55 -0800 Subject: [PATCH] fix findDOMPoint for non-empty void node offsets --- packages/slate-react/src/utils/find-dom-point.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/slate-react/src/utils/find-dom-point.js b/packages/slate-react/src/utils/find-dom-point.js index 6414fc4d3..e6c839a2b 100644 --- a/packages/slate-react/src/utils/find-dom-point.js +++ b/packages/slate-react/src/utils/find-dom-point.js @@ -21,14 +21,17 @@ function findDOMPoint(point, win = window) { for (const text of texts) { const node = text.childNodes[0] - const length = text.hasAttribute('data-slate-length') - ? parseInt(text.getAttribute('data-slate-length'), 10) - : node.textContent.length + const domLength = node.textContent.length + let slateLength = domLength - const end = start + length + if (text.hasAttribute('data-slate-length')) { + slateLength = parseInt(text.getAttribute('data-slate-length'), 10) + } + + const end = start + slateLength if (point.offset <= end) { - const offset = Math.max(0, point.offset - start) + const offset = Math.min(domLength, Math.max(0, point.offset - start)) return { node, offset } }