mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 06:31:28 +02:00
fix findDOMPoint for non-empty void node offsets
This commit is contained in:
@@ -21,14 +21,17 @@ function findDOMPoint(point, win = window) {
|
|||||||
|
|
||||||
for (const text of texts) {
|
for (const text of texts) {
|
||||||
const node = text.childNodes[0]
|
const node = text.childNodes[0]
|
||||||
const length = text.hasAttribute('data-slate-length')
|
const domLength = node.textContent.length
|
||||||
? parseInt(text.getAttribute('data-slate-length'), 10)
|
let slateLength = domLength
|
||||||
: node.textContent.length
|
|
||||||
|
|
||||||
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) {
|
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 }
|
return { node, offset }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user