🎨 Refactor code structure

This commit is contained in:
2025-04-25 18:34:22 +08:00
parent e87d5ec929
commit 946075f25d
4 changed files with 85 additions and 100 deletions

View File

@@ -10,7 +10,6 @@ import {
getTabExtensions, getTabExtensions,
updateTabConfig, updateTabConfig,
createWheelZoomHandler, createWheelZoomHandler,
applyFontSize,
updateStats updateStats
} from './extensions'; } from './extensions';
@@ -68,7 +67,7 @@ const createEditor = () => {
editorStore.setEditorView(view); editorStore.setEditorView(view);
// 应用初始字体大小 // 应用初始字体大小
applyFontSize(view, configStore.config.fontSize); editorStore.applyFontSize();
// 立即更新统计信息,不等待用户交互 // 立即更新统计信息,不等待用户交互
updateStats(view, editorStore.updateDocumentStats); updateStats(view, editorStore.updateDocumentStats);
@@ -98,9 +97,7 @@ watch(() => configStore.config.tabType, reconfigureTabSettings);
// 监听字体大小变化 // 监听字体大小变化
watch(() => configStore.config.fontSize, () => { watch(() => configStore.config.fontSize, () => {
if (editorStore.editorView) { editorStore.applyFontSize();
applyFontSize(editorStore.editorView as EditorView, configStore.config.fontSize);
}
}); });
onMounted(() => { onMounted(() => {

View File

@@ -1,5 +1,3 @@
import {EditorView} from '@codemirror/view';
// 处理滚轮缩放字体的事件处理函数 // 处理滚轮缩放字体的事件处理函数
export const createWheelZoomHandler = ( export const createWheelZoomHandler = (
increaseFontSize: () => void, increaseFontSize: () => void,
@@ -22,14 +20,3 @@ export const createWheelZoomHandler = (
} }
}; };
}; };
// 应用字体大小到编辑器
export const applyFontSize = (view: EditorView, fontSize: number) => {
if (!view) return;
// 更新编辑器的字体大小
const editorDOM = view.dom;
if (editorDOM) {
editorDOM.style.fontSize = `${fontSize}px`;
}
};

View File

@@ -1,6 +1,6 @@
import { defineStore } from 'pinia'; import {defineStore} from 'pinia';
import { ref } from 'vue'; import {ref} from 'vue';
import { EditorConfig, TabType } from '@/types/config'; import {EditorConfig} from '@/types/config';
// 字体大小范围 // 字体大小范围
const MIN_FONT_SIZE = 12; const MIN_FONT_SIZE = 12;

View File

@@ -34,6 +34,7 @@ export const useEditorStore = defineStore('editor', () => {
const editorDOM = editorView.value.dom; const editorDOM = editorView.value.dom;
if (editorDOM) { if (editorDOM) {
editorDOM.style.fontSize = `${configStore.config.fontSize}px`; editorDOM.style.fontSize = `${configStore.config.fontSize}px`;
editorView.value?.requestMeasure();
} }
} }