🎨 Refactor code structure
This commit is contained in:
@@ -10,7 +10,6 @@ import {
|
||||
getTabExtensions,
|
||||
updateTabConfig,
|
||||
createWheelZoomHandler,
|
||||
applyFontSize,
|
||||
updateStats
|
||||
} from './extensions';
|
||||
|
||||
@@ -68,7 +67,7 @@ const createEditor = () => {
|
||||
editorStore.setEditorView(view);
|
||||
|
||||
// 应用初始字体大小
|
||||
applyFontSize(view, configStore.config.fontSize);
|
||||
editorStore.applyFontSize();
|
||||
|
||||
// 立即更新统计信息,不等待用户交互
|
||||
updateStats(view, editorStore.updateDocumentStats);
|
||||
@@ -98,9 +97,7 @@ watch(() => configStore.config.tabType, reconfigureTabSettings);
|
||||
|
||||
// 监听字体大小变化
|
||||
watch(() => configStore.config.fontSize, () => {
|
||||
if (editorStore.editorView) {
|
||||
applyFontSize(editorStore.editorView as EditorView, configStore.config.fontSize);
|
||||
}
|
||||
editorStore.applyFontSize();
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
|
@@ -1,5 +1,3 @@
|
||||
import {EditorView} from '@codemirror/view';
|
||||
|
||||
// 处理滚轮缩放字体的事件处理函数
|
||||
export const createWheelZoomHandler = (
|
||||
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`;
|
||||
}
|
||||
};
|
@@ -1,6 +1,6 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { EditorConfig, TabType } from '@/types/config';
|
||||
import {defineStore} from 'pinia';
|
||||
import {ref} from 'vue';
|
||||
import {EditorConfig} from '@/types/config';
|
||||
|
||||
// 字体大小范围
|
||||
const MIN_FONT_SIZE = 12;
|
||||
|
@@ -34,6 +34,7 @@ export const useEditorStore = defineStore('editor', () => {
|
||||
const editorDOM = editorView.value.dom;
|
||||
if (editorDOM) {
|
||||
editorDOM.style.fontSize = `${configStore.config.fontSize}px`;
|
||||
editorView.value?.requestMeasure();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user