1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-18 05:01:17 +02:00

fix findDOMPoint for non-empty void node offsets

This commit is contained in:
Ian Storm Taylor
2018-11-06 14:01:55 -08:00
parent 9446bcbf6d
commit 836ab1d494

View File

@@ -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 }
}