fix focus loss

This commit is contained in:
Michael Freno
2025-12-20 13:42:31 -05:00
parent e9a2b00254
commit 8e7a93e762
2 changed files with 29 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
import { Show } from "solid-js";
import { Show, untrack, createEffect, on } from "solid-js";
import { createTiptapEditor, useEditorHTML } from "solid-tiptap";
import StarterKit from "@tiptap/starter-kit";
import Link from "@tiptap/extension-link";
@@ -118,10 +118,26 @@ export default function TextEditor(props: TextEditorProps) {
],
content: props.preSet || `<p><em><b>Hello!</b> World</em></p>`,
onUpdate: ({ editor }) => {
props.updateContent(editor.getHTML());
untrack(() => {
props.updateContent(editor.getHTML());
});
}
}));
// Update editor content when preSet changes (e.g., when data loads), but only if editor exists and content is different
createEffect(
on(
() => props.preSet,
(newContent) => {
const instance = editor();
if (instance && newContent && instance.getHTML() !== newContent) {
instance.commands.setContent(newContent, false); // false = don't emit update event
}
},
{ defer: true }
)
);
const setLink = () => {
const instance = editor();
if (!instance) return;