fix(ui): add null guard for missing element in caret utils
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user