Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

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

Saul-Mironeade317d26b31
diff --git a/blocksuite/affine/shared/src/utils/dom/point-to-range.ts b/blocksuite/affine/shared/src/utils/dom/point-to-range.ts
index 98ea0ecc57..9d842f8159 100644
--- a/blocksuite/affine/shared/src/utils/dom/point-to-range.ts
+++ b/blocksuite/affine/shared/src/utils/dom/point-to-range.ts
@@ -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);