fix(editor): caret can be null in firefox (#9438)

Fix: https://toeverything.sentry.io/issues/6185588184/events/b205b6caf0224b51882c1d10bb3dd9bc/
This commit is contained in:
Saul-Mirone
2024-12-30 14:44:11 +00:00
parent a9f890017e
commit ade317d26b

View File

@@ -9,7 +9,7 @@ declare global {
): {
offsetNode: Node;
offset: number;
};
} | null;
}
}
@@ -23,6 +23,9 @@ export function caretRangeFromPoint(
): Range | null {
if (IS_FIREFOX) {
const caret = document.caretPositionFromPoint(clientX, clientY);
if (!caret) {
return null;
}
// TODO handle caret is covered by popup
const range = document.createRange();
range.setStart(caret.offsetNode, caret.offset);