Skip to content

Commit d820757

Browse files
committed
fix(save-and-restore): use correct parent
1 parent ba2101d commit d820757

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/range-save-restore.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ function isChildOf (parent, possibleChild) {
1919
}
2020

2121
function startContainerIsChild (range) {
22-
const parent = range.endContainer.parentElement
22+
const parent = range.commonAncestorContainer
23+
if (parent.nodeType === 3) return false // if we are on the text node it can't be a parent
2324
const possibleChild = range.startContainer.parentElement
2425
return isChildOf(parent, possibleChild)
2526
}
2627

2728
function endContainerIsChild (range) {
28-
const parent = range.startContainer.parentElement
29+
const parent = range.commonAncestorContainer
30+
if (parent.nodeType === 3) return false // if we are on the text node it can't be a parent
2931
const possibleChild = range.endContainer.parentElement
3032
return isChildOf(parent, possibleChild)
3133
}

0 commit comments

Comments
 (0)