diff --git a/apps/client/src/widgets/note_title.tsx b/apps/client/src/widgets/note_title.tsx index dac6a498e0..34b27c9298 100644 --- a/apps/client/src/widgets/note_title.tsx +++ b/apps/client/src/widgets/note_title.tsx @@ -66,6 +66,7 @@ export default function NoteTitleWidget(props: {className?: string}) { useEffect(() => { if (pendingSelect.current && textBoxRef.current && document.activeElement === textBoxRef.current) { textBoxRef.current.select(); + pendingSelect.current = false; } }, [title]); diff --git a/apps/client/src/widgets/sidebar/HighlightsList.tsx b/apps/client/src/widgets/sidebar/HighlightsList.tsx index 580591bd63..d0c447c283 100644 --- a/apps/client/src/widgets/sidebar/HighlightsList.tsx +++ b/apps/client/src/widgets/sidebar/HighlightsList.tsx @@ -233,18 +233,19 @@ function extractHighlightsFromTextEditor(editor: CKTextEditor) { if (Object.values(attrs).some(Boolean)) { // Get HTML content from DOM (includes nested elements like math) let html = item.data; - const modelPos = editor.model.createPositionAt(item.textNode, "before"); - const viewPos = editor.editing.mapper.toViewPosition(modelPos); - const domPos = editor.editing.view.domConverter.viewPositionToDom(viewPos); - if (domPos?.parent instanceof HTMLElement) { - // Get the formatting span's innerHTML (includes math elements) - html = domPos.parent.innerHTML; + try { + const modelPos = editor.model.createPositionAt(item.textNode, "before"); + const viewPos = editor.editing.mapper.toViewPosition(modelPos); + const domPos = editor.editing.view.domConverter.viewPositionToDom(viewPos); + if (domPos?.parent instanceof HTMLElement) { + // Get the formatting span's innerHTML (includes math elements) + html = domPos.parent.innerHTML; + } + } catch { + // During change:data events, the view may not be fully synchronized with the model. + // Fall back to using the raw text data. } - // Skip if we already have this exact content (same parent element) - const prev = result[result.length - 1]; - if (prev?.text === html) continue; - result.push({ id: randomString(), text: html,