feat(store): add editor state to useCodeEditor store

This commit is contained in:
cfngc4594 2025-02-24 13:17:16 +08:00
parent adf59f8132
commit 5cabdda667

View File

@ -6,15 +6,19 @@ import { SupportedLanguage } from "@/constants/language";
import { MonacoLanguageClient } from "monaco-languageclient";
interface CodeEditorState {
editor: monaco.editor.IStandaloneCodeEditor | null;
language: SupportedLanguage;
languageClient: MonacoLanguageClient | null;
setEditor: (editor: monaco.editor.IStandaloneCodeEditor | null) => void;
setLanguage: (language: SupportedLanguage) => void;
setLanguageClient: (languageClient: MonacoLanguageClient | null) => void;
}
export const useCodeEditorState = create<CodeEditorState>((set) => ({
editor: null,
language: DEFAULT_LANGUAGE,
languageClient: null,
setEditor: (editor) => set({ editor }),
setLanguage: (language) => set({ language }),
setLanguageClient: (languageClient) => set({ languageClient }),
}));
@ -23,5 +27,5 @@ export const useCodeEditorOption = create<monaco.editor.IEditorConstructionOptio
fontSize: CODE_EDITOR_OPTIONS.fontSize,
lineHeight: CODE_EDITOR_OPTIONS.lineHeight,
setFontSize: (fontSize: number) => set({ fontSize }),
setLineHeight: (lineHeight: number) => set({ lineHeight })
}))
setLineHeight: (lineHeight: number) => set({ lineHeight }),
}));