Prevent exception on Firefox due to getSelection returning null (#57)

This commit is contained in:
Protected
2025-05-13 12:49:18 +00:00
committed by GitHub
parent 052123beaf
commit 55f1a28406
+2
View File
@@ -158,12 +158,14 @@ const setSelectionTo = (target, collapse) => {
}
if (range) {
const sel = range.startContainer.ownerDocument.defaultView.getSelection()
if (sel) {
sel.removeAllRanges()
if (collapse === -1) range.collapse(true)
else if (collapse === 1) range.collapse()
sel.addRange(range)
}
}
}
const getDirection = doc => {
const { defaultView } = doc