diff --git a/webui/src/components/Editor.tsx b/webui/src/components/Editor.tsx index 2566079..d190e3c 100644 --- a/webui/src/components/Editor.tsx +++ b/webui/src/components/Editor.tsx @@ -50,13 +50,24 @@ interface EditorProps { fontSize?: number; } +const STORAGE_KEY = "minimax-editor-content"; + export const Editor = forwardRef(function Editor( { initialValue = "", onChange, onReady, fontSize = 14 }, ref ) { const textareaRef = useRef(null); const editorRef = useRef(null); - const [content, setContent] = useState(initialValue); + + const getInitialContent = () => { + if (typeof window !== "undefined") { + const saved = localStorage.getItem(STORAGE_KEY); + return saved || initialValue; + } + return initialValue; + }; + + const [content, setContent] = useState(getInitialContent); useImperativeHandle(ref, () => editorRef.current); @@ -100,6 +111,11 @@ export const Editor = forwardRef(function Editor( editor.on("change", (instance: any, changes: any) => { const newContent = instance.getValue(); setContent(newContent); + + if (typeof window !== "undefined") { + localStorage.setItem(STORAGE_KEY, newContent); + } + onChange?.(instance, changes); }); @@ -129,7 +145,7 @@ export const Editor = forwardRef(function Editor(