diff --git a/package.json b/package.json index 419766bc..b94bdb21 100644 --- a/package.json +++ b/package.json @@ -10,14 +10,23 @@ "tauri": "tauri" }, "dependencies": { + "@babel/runtime": "^7.28.2", + "@codemirror/lang-go": "^6.0.1", + "@codemirror/lang-javascript": "^6.2.4", + "@codemirror/lang-python": "^6.2.1", + "@codemirror/state": "^6.5.2", + "@codemirror/view": "^6.38.1", "@tauri-apps/api": "^2", "@tauri-apps/plugin-dialog": "^2.3.2", "@tauri-apps/plugin-opener": "^2", "@tauri-apps/plugin-shell": "^2.3.0", + "@uiw/codemirror-themes-all": "^4.24.2", "@vueuse/core": "^13.6.0", + "codemirror": "^6.0.2", "lodash-es": "^4.17.21", "lucide-vue-next": "^0.539.0", "vue": "^3.5.13", + "vue-codemirror": "^6.1.1", "vue3-markdown-it": "^1.0.10" }, "devDependencies": { diff --git a/src-tauri/src/config.rs b/src-tauri/src/config.rs index 9fc1e39b..15c3d117 100644 --- a/src-tauri/src/config.rs +++ b/src-tauri/src/config.rs @@ -10,6 +10,13 @@ use tauri::{AppHandle, Manager, command}; static CONFIG_MANAGER: Mutex> = Mutex::new(None); +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct EditorConfig { + pub indent_with_tab: Option, // 是否使用 tab 缩进 + pub tab_size: Option, // tab 缩进, 空格数,默认为 2 + pub theme: Option, // 编辑器主题 +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AppConfig { pub log_directory: Option, @@ -17,6 +24,7 @@ pub struct AppConfig { pub keep_log_days: Option, pub theme: Option, pub plugins: Option>, + pub editor: Option, } impl Default for AppConfig { @@ -27,6 +35,11 @@ impl Default for AppConfig { keep_log_days: Some(30), theme: Some("system".to_string()), plugins: Some(vec![]), + editor: Some(EditorConfig { + indent_with_tab: Some(true), + tab_size: Some(2), + theme: Some("githubLight".to_string()), + }), } } } @@ -75,6 +88,16 @@ impl ConfigManager { // 合并插件配置(现有配置 + 默认配置中缺失的插件) config.plugins = Self::merge_plugins_config(config.plugins, app_handle); + // 检查并设置 editor 默认配置 + if config.editor.is_none() { + config.editor = Some(EditorConfig { + indent_with_tab: Some(true), + tab_size: Some(2), + theme: Some("githubLight".to_string()), + }); + println!("读取配置 -> 添加默认 editor 配置"); + } + Ok(config) } Err(e) => { @@ -170,6 +193,11 @@ impl ConfigManager { keep_log_days: Some(30), theme: Some("system".to_string()), plugins: Self::get_default_plugins_config(app_handle), + editor: Some(EditorConfig { + indent_with_tab: Some(true), + tab_size: Some(2), + theme: Some("githubLight".to_string()), + }), } } diff --git a/src/components/CodeEditor.vue b/src/components/CodeEditor.vue index 286ca252..25851c0a 100644 --- a/src/components/CodeEditor.vue +++ b/src/components/CodeEditor.vue @@ -1,40 +1,19 @@ \ No newline at end of file +onMounted(async () => { + await initializeEditor() +}) + diff --git a/src/components/Settings.vue b/src/components/Settings.vue index eedc6a89..341634cc 100644 --- a/src/components/Settings.vue +++ b/src/components/Settings.vue @@ -11,6 +11,11 @@ + + +