fix(text): note with empty table carries over to new notes

This commit is contained in:
Elian Doran 2025-11-22 11:52:16 +02:00
parent 9b3ca65492
commit 6040eea3bd
No known key found for this signature in database
2 changed files with 5 additions and 8 deletions

View File

@ -20,7 +20,6 @@ export interface CKEditorApi {
} }
interface CKEditorWithWatchdogProps extends Pick<HTMLProps<HTMLDivElement>, "className" | "tabIndex"> { interface CKEditorWithWatchdogProps extends Pick<HTMLProps<HTMLDivElement>, "className" | "tabIndex"> {
content: string | undefined;
contentLanguage: string | null | undefined; contentLanguage: string | null | undefined;
isClassicEditor?: boolean; isClassicEditor?: boolean;
watchdogRef: RefObject<EditorWatchdog>; watchdogRef: RefObject<EditorWatchdog>;
@ -35,7 +34,7 @@ interface CKEditorWithWatchdogProps extends Pick<HTMLProps<HTMLDivElement>, "cla
containerRef?: RefObject<HTMLDivElement>; containerRef?: RefObject<HTMLDivElement>;
} }
export default function CKEditorWithWatchdog({ containerRef: externalContainerRef, content, contentLanguage, className, tabIndex, isClassicEditor, watchdogRef: externalWatchdogRef, watchdogConfig, onNotificationWarning, onWatchdogStateChange, onChange, onEditorInitialized, editorApi, templates }: CKEditorWithWatchdogProps) { export default function CKEditorWithWatchdog({ containerRef: externalContainerRef, contentLanguage, className, tabIndex, isClassicEditor, watchdogRef: externalWatchdogRef, watchdogConfig, onNotificationWarning, onWatchdogStateChange, onChange, onEditorInitialized, editorApi, templates }: CKEditorWithWatchdogProps) {
const containerRef = useSyncedRef<HTMLDivElement>(externalContainerRef, null); const containerRef = useSyncedRef<HTMLDivElement>(externalContainerRef, null);
const watchdogRef = useRef<EditorWatchdog>(null); const watchdogRef = useRef<EditorWatchdog>(null);
const [ uiLanguage ] = useTriliumOption("locale"); const [ uiLanguage ] = useTriliumOption("locale");
@ -185,9 +184,6 @@ export default function CKEditorWithWatchdog({ containerRef: externalContainerRe
return () => watchdog.destroy(); return () => watchdog.destroy();
}, [ contentLanguage, templates, uiLanguage ]); }, [ contentLanguage, templates, uiLanguage ]);
// React to content changes.
useEffect(() => editor?.setData(content ?? ""), [ editor, content ]);
// React to notification warning callback. // React to notification warning callback.
useEffect(() => { useEffect(() => {
if (!onNotificationWarning || !editor) return; if (!onNotificationWarning || !editor) return;

View File

@ -27,7 +27,7 @@ import { deferred } from "@triliumnext/commons";
*/ */
export default function EditableText({ note, parentComponent, ntxId, noteContext }: TypeWidgetProps) { export default function EditableText({ note, parentComponent, ntxId, noteContext }: TypeWidgetProps) {
const containerRef = useRef<HTMLDivElement>(null); const containerRef = useRef<HTMLDivElement>(null);
const [ content, setContent ] = useState<string>(); const contentRef = useRef<string>("");
const watchdogRef = useRef<EditorWatchdog>(null); const watchdogRef = useRef<EditorWatchdog>(null);
const editorApiRef = useRef<CKEditorApi>(null); const editorApiRef = useRef<CKEditorApi>(null);
const refreshTouchBarRef = useRef<() => void>(null); const refreshTouchBarRef = useRef<() => void>(null);
@ -55,7 +55,8 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext
}; };
}, },
onContentChange(newContent) { onContentChange(newContent) {
setContent(newContent); contentRef.current = newContent;
watchdogRef.current?.editor?.setData(newContent);
} }
}); });
const templates = useTemplates(); const templates = useTemplates();
@ -215,7 +216,6 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext
containerRef={containerRef} containerRef={containerRef}
className={`note-detail-editable-text-editor use-tn-links ${codeBlockWordWrap ? "word-wrap" : ""}`} className={`note-detail-editable-text-editor use-tn-links ${codeBlockWordWrap ? "word-wrap" : ""}`}
tabIndex={300} tabIndex={300}
content={content}
contentLanguage={language} contentLanguage={language}
isClassicEditor={isClassicEditor} isClassicEditor={isClassicEditor}
editorApi={editorApiRef} editorApi={editorApiRef}
@ -245,6 +245,7 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext
} }
initialized.current.resolve(); initialized.current.resolve();
editor.setData(contentRef.current ?? "");
parentComponent?.triggerEvent("textEditorRefreshed", { ntxId, editor }); parentComponent?.triggerEvent("textEditorRefreshed", { ntxId, editor });
}} }}
/>} />}