mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 15:55:52 +01:00
chore(react/ribbon): load current attributes in editor
This commit is contained in:
@@ -2,6 +2,7 @@ import { CKTextEditor, type AttributeEditor, type EditorConfig, type ModelPositi
|
||||
import { useEffect, useRef } from "preact/compat";
|
||||
|
||||
interface CKEditorOpts {
|
||||
currentValue?: string;
|
||||
className: string;
|
||||
tabIndex?: number;
|
||||
config: EditorConfig;
|
||||
@@ -12,7 +13,7 @@ interface CKEditorOpts {
|
||||
onClick?: (pos?: ModelPosition | null) => void;
|
||||
}
|
||||
|
||||
export default function CKEditor({ className, tabIndex, editor, config, disableNewlines, disableSpellcheck, onChange, onClick }: CKEditorOpts) {
|
||||
export default function CKEditor({ currentValue, className, tabIndex, editor, config, disableNewlines, disableSpellcheck, onChange, onClick }: CKEditorOpts) {
|
||||
const editorContainerRef = useRef<HTMLDivElement>(null);
|
||||
const textEditorRef = useRef<CKTextEditor>(null);
|
||||
|
||||
@@ -44,9 +45,18 @@ export default function CKEditor({ className, tabIndex, editor, config, disableN
|
||||
if (onChange) {
|
||||
textEditor.model.document.on("change:data", onChange);
|
||||
}
|
||||
|
||||
if (currentValue) {
|
||||
textEditor.setData(currentValue);
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!textEditorRef.current) return;
|
||||
textEditorRef.current.setData(currentValue ?? "");
|
||||
}, [ currentValue ]);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={editorContainerRef}
|
||||
|
||||
Reference in New Issue
Block a user