Skip to content

Commit 54818d0

Browse files
committed
fix (core): 修复编辑器修改后配置未更新
1 parent 841aa32 commit 54818d0

3 files changed

Lines changed: 54 additions & 15 deletions

File tree

src/App.vue

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</div>
2222
</div>
2323
<div class="flex-1 overflow-hidden">
24-
<CodeEditor v-model="code" class="h-full" :language="currentLanguage"/>
24+
<CodeEditor v-model="code" class="h-full" :language="currentLanguage" :editor-config="editorConfig" :key="editorConfigKey"/>
2525
</div>
2626
</div>
2727

@@ -44,7 +44,7 @@
4444
<About v-if="showAbout" @close="closeAbout"/>
4545

4646
<!-- 设置组件 -->
47-
<Settings v-if="showSettings" @close="closeSettings"/>
47+
<Settings v-if="showSettings" @close="closeSettings" @settings-changed="handleSettingsChanged"/>
4848

4949
<!-- 更新组件 -->
5050
<Update v-if="showUpdate" @close="closeUpdate"/>
@@ -55,7 +55,7 @@
5555
</template>
5656

5757
<script setup lang="ts">
58-
import { onMounted, onUnmounted } from 'vue'
58+
import { onMounted, onUnmounted, ref, watch } from 'vue'
5959
import AppHeader from './components/AppHeader.vue'
6060
import CodeEditor from './components/CodeEditor.vue'
6161
import OutputPanel from './components/OutputPanel.vue'
@@ -70,6 +70,7 @@ import { useCodeExecution } from './composables/useCodeExecution'
7070
import { useLanguageManager } from './composables/useLanguageManager'
7171
import { useEventManager } from './composables/useEventManager'
7272
import { useAppState } from './composables/useAppState'
73+
import { useEditorConfig } from './composables/useEditorConfig'
7374
import Update from './components/Update.vue'
7475
7576
const toast = useToast()
@@ -109,6 +110,34 @@ const {
109110
closeUpdate
110111
} = useAppState()
111112
113+
// 编辑器配置管理
114+
const {
115+
editorConfig,
116+
loadConfig: loadEditorConfig
117+
} = useEditorConfig()
118+
119+
// 强制刷新 CodeEditor 组件的 key
120+
const editorConfigKey = ref(0)
121+
122+
// 处理设置变更
123+
const handleSettingsChanged = (config: any) => {
124+
console.log('主组件接收到设置变更:', config)
125+
// 延迟一点点再刷新,减少闪烁
126+
setTimeout(() => {
127+
editorConfigKey.value++
128+
}, 50)
129+
}
130+
131+
// 监听编辑器配置变化
132+
watch(editorConfig, (newConfig) => {
133+
if (newConfig) {
134+
console.log('编辑器配置更新,刷新编辑器组件')
135+
setTimeout(() => {
136+
editorConfigKey.value++
137+
}, 50)
138+
}
139+
}, { deep: true })
140+
112141
const { initializeEventListeners, cleanupEventListeners } = useEventManager({
113142
showAbout,
114143
showSettings,
@@ -131,6 +160,7 @@ window.addEventListener('contextmenu', (e) => e.preventDefault(), false)
131160
132161
onMounted(async () => {
133162
await initialize()
163+
await loadEditorConfig()
134164
await initializeEventListeners()
135165
136166
// 触发 app-ready 事件,通知主进程

src/components/Settings.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<!-- 编辑器配置 -->
1515
<template #editor>
16-
<Editor v-if="activeTab === 'editor'"/>
16+
<Editor v-if="activeTab === 'editor'" @settings-changed="handleEditorSettingsChanged" @error="handleEditorError"/>
1717
</template>
1818

1919
<!-- 语言配置 -->
@@ -43,8 +43,21 @@ const tabsData = [
4343
4444
const emit = defineEmits<{
4545
close: []
46+
'settings-changed': [config: any]
4647
}>()
4748
49+
// 处理编辑器设置变更
50+
const handleEditorSettingsChanged = (config: any) => {
51+
console.log('设置模态框接收到编辑器配置变更:', config)
52+
// 向上传递事件到主组件
53+
emit('settings-changed', config)
54+
}
55+
56+
// 处理编辑器错误
57+
const handleEditorError = (message: string) => {
58+
console.error('编辑器设置错误:', message)
59+
}
60+
4861
const closeSettings = () => {
4962
isVisible.value = false
5063
setTimeout(() => {

src/components/setting/Editor.vue

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
<div class="flex gap-2">
88
<input v-model="editorConfig.indent_with_tab"
99
type="checkbox"
10-
placeholder="超时时间(秒),默认 30 秒"
11-
class="flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-transparent text-sm"/>
10+
class="px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-transparent text-sm"/>
1211
</div>
1312
</div>
1413

@@ -17,12 +16,12 @@
1716
缩进空格数
1817
</label>
1918
<div class="flex gap-2">
20-
<input v-model="editorConfig.tab_size"
19+
<input v-model.number="editorConfig.tab_size"
2120
type="number"
22-
:disabled="!editorConfig.indent_with_tab"
23-
placeholder="缩进空格数,默认 2 秒"
24-
class="flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-transparent text-sm"
25-
:class="[!editorConfig.indent_with_tab ? 'opacity-50 cursor-not-allowed' : '']"/>
21+
min="1"
22+
max="8"
23+
placeholder="缩进空格数,默认 2"
24+
class="flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-transparent text-sm"/>
2625
</div>
2726
</div>
2827

@@ -31,10 +30,7 @@
3130
编辑器主题
3231
</label>
3332
<div class="flex gap-2">
34-
<Select v-model="editorConfig.theme"
35-
class="w-1/4"
36-
placeholder="选择编辑器主题"
37-
:options="themeOptions"/>
33+
<Select v-model="editorConfig.theme" class="w-1/4" placeholder="选择编辑器主题" :options="themeOptions"/>
3834
</div>
3935
</div>
4036
</div>

0 commit comments

Comments
 (0)