Skip to content

Commit 137bb41

Browse files
committed
feat (core): 支持编辑器设置文字大小
1 parent 36e7063 commit 137bb41

6 files changed

Lines changed: 24 additions & 4 deletions

File tree

src-tauri/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub struct EditorConfig {
1515
pub indent_with_tab: Option<bool>, // 是否使用 tab 缩进
1616
pub tab_size: Option<u32>, // tab 缩进, 空格数,默认为 2
1717
pub theme: Option<String>, // 编辑器主题
18+
pub font_size: Option<u32>, // 编辑器字体大小
1819
}
1920

2021
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -39,6 +40,7 @@ impl Default for AppConfig {
3940
indent_with_tab: Some(true),
4041
tab_size: Some(2),
4142
theme: Some("githubLight".to_string()),
43+
font_size: Some(14),
4244
}),
4345
}
4446
}
@@ -94,6 +96,7 @@ impl ConfigManager {
9496
indent_with_tab: Some(true),
9597
tab_size: Some(2),
9698
theme: Some("githubLight".to_string()),
99+
font_size: Some(14),
97100
});
98101
println!("读取配置 -> 添加默认 editor 配置");
99102
}
@@ -197,6 +200,7 @@ impl ConfigManager {
197200
indent_with_tab: Some(true),
198201
tab_size: Some(2),
199202
theme: Some("githubLight".to_string()),
203+
font_size: Some(14),
200204
}),
201205
}
202206
}

src-tauri/src/setup/menus/app.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use log::info;
2+
#[allow(unused_imports)]
3+
use tauri::Manager;
24
use tauri::{
35
AppHandle, Emitter,
46
menu::{MenuItemBuilder, Submenu, SubmenuBuilder},

src/components/CodeEditor.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="flex bg-white h-full relative">
33
<Codemirror v-if="isReady"
4-
style="width: 100%; height: 100%"
4+
:style="{ width: '100%', height: '100%', fontSize: editorConfig?.font_size ? `${editorConfig.font_size}px` : undefined }"
55
:model-value="modelValue"
66
:extensions="extensions"
77
:indent-with-tab="editorConfig?.indent_with_tab"

src/components/setting/Editor.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818
</div>
1919
</div>
2020

21+
<div>
22+
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
23+
字体大小
24+
</label>
25+
<div class="flex gap-2">
26+
<Number v-model="editorConfig.font_size" :min="1" :max="30" placeholder="字体大小"/>
27+
</div>
28+
</div>
29+
2130
<div>
2231
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
2332
编辑器主题

src/composables/useCodeMirrorEditor.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ interface EditorConfig
6666
theme?: string
6767
indent_with_tab?: boolean
6868
tab_size?: number
69+
font_size?: number
6970
}
7071

7172
interface Props
@@ -221,7 +222,8 @@ export function useCodeMirrorEditor(props: Props)
221222
editorConfig.value = {
222223
theme: 'githubLight',
223224
indent_with_tab: true,
224-
tab_size: 2
225+
tab_size: 2,
226+
font_size: 14
225227
}
226228
await updateExtensions()
227229
}
@@ -234,7 +236,8 @@ export function useCodeMirrorEditor(props: Props)
234236
editorConfig.value = {
235237
theme: 'githubLight',
236238
indent_with_tab: true,
237-
tab_size: 2
239+
tab_size: 2,
240+
font_size: 14
238241
}
239242
await updateExtensions()
240243
}

src/composables/useEditorConfig.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface EditorConfig
88
tab_size?: number
99
theme?: string
1010
indent_with_tab?: boolean
11+
font_size?: number
1112
}
1213

1314
interface ThemeOption
@@ -149,7 +150,8 @@ export function useEditorConfig(emit?: any)
149150
editorConfig.value = {
150151
indent_with_tab: true,
151152
tab_size: 2,
152-
theme: 'githubLight'
153+
theme: 'githubLight',
154+
font_size: 14
153155
}
154156
}
155157

0 commit comments

Comments
 (0)