fix(ui): add null guard for missing element in caret utils

This commit is contained in:
2026-04-26 16:01:53 -04:00
parent 688ae224ab
commit a1bcc4bfb9
@@ -93,6 +93,7 @@ function locateOffset(el, offset) {
}
export function getCaretOffset(el) {
if (!el) return 0;
const sel = typeof window !== 'undefined' ? window.getSelection() : null;
if (!sel || sel.rangeCount === 0) return 0;
const range = sel.getRangeAt(0);
@@ -101,6 +102,7 @@ export function getCaretOffset(el) {
}
export function getCaretRange(el) {
if (!el) return null;
const sel = typeof window !== 'undefined' ? window.getSelection() : null;
if (!sel || sel.rangeCount === 0) return null;
const range = sel.getRangeAt(0);