1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-21 14:41:23 +02:00

FIX findPoint offset may be include zero width string (#2982)

* FIX point offset may be include zero width string

* fix prettier style

* FIX prettier style
This commit is contained in:
ibone
2019-09-09 01:11:49 +08:00
committed by Ian Storm Taylor
parent ca73f2a671
commit fb728f4754

View File

@@ -51,7 +51,11 @@ function findPoint(nativeNode, nativeOffset, editor) {
// into \r\n. The bug causes a loop when slate-react attempts to reposition // into \r\n. The bug causes a loop when slate-react attempts to reposition
// its cursor to match the native position. Use textContent.length instead. // its cursor to match the native position. Use textContent.length instead.
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10291116/ // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10291116/
offset = range.cloneContents().textContent.length const fragment = range.cloneContents()
const zeroWidthNodes = fragment.querySelectorAll(
`[${DATA_ATTRS.ZERO_WIDTH}]`
)
offset = fragment.textContent.length - zeroWidthNodes.length
} else { } else {
// For void nodes, the element with the offset key will be a cousin, not an // For void nodes, the element with the offset key will be a cousin, not an
// ancestor, so find it by going down from the nearest void parent. // ancestor, so find it by going down from the nearest void parent.