From 3e20f47b8ec73c2bed6c5d1275b8575c0da6bc49 Mon Sep 17 00:00:00 2001 From: landaiqing Date: Thu, 5 Jun 2025 02:11:36 +0800 Subject: [PATCH] :art: Updated --- .../voidraft/internal/models/models.ts | 16 - .../internal/services/dialogservice.ts | 19 + .../internal/services/documentservice.ts | 67 +-- .../voidraft/internal/services/index.ts | 2 + .../voidraft/internal/services/models.ts | 135 ----- frontend/src/i18n/locales/en-US.ts | 6 +- frontend/src/i18n/locales/zh-CN.ts | 6 +- frontend/src/stores/configStore.ts | 14 +- .../editor/extensions/autoSaveExtension.ts | 6 + .../src/views/settings/pages/EditingPage.vue | 66 +-- .../src/views/settings/pages/GeneralPage.vue | 173 +++--- internal/models/config.go | 8 +- internal/services/config_service.go | 2 - internal/services/dialog_service.go | 66 +++ internal/services/document_diff.go | 306 ----------- internal/services/document_service.go | 509 +++++------------- internal/services/service_manager.go | 6 + 17 files changed, 354 insertions(+), 1053 deletions(-) create mode 100644 frontend/bindings/voidraft/internal/services/dialogservice.ts create mode 100644 internal/services/dialog_service.go delete mode 100644 internal/services/document_diff.go diff --git a/frontend/bindings/voidraft/internal/models/models.ts b/frontend/bindings/voidraft/internal/models/models.ts index b2d1592..99fcb07 100644 --- a/frontend/bindings/voidraft/internal/models/models.ts +++ b/frontend/bindings/voidraft/internal/models/models.ts @@ -299,16 +299,6 @@ export class EditingConfig { */ "autoSaveDelay": number; - /** - * 变更字符阈值 - */ - "changeThreshold": number; - - /** - * 最小保存间隔(毫秒) - */ - "minSaveInterval": number; - /** Creates a new EditingConfig instance. */ constructor($$source: Partial = {}) { if (!("fontSize" in $$source)) { @@ -335,12 +325,6 @@ export class EditingConfig { if (!("autoSaveDelay" in $$source)) { this["autoSaveDelay"] = 0; } - if (!("changeThreshold" in $$source)) { - this["changeThreshold"] = 0; - } - if (!("minSaveInterval" in $$source)) { - this["minSaveInterval"] = 0; - } Object.assign(this, $$source); } diff --git a/frontend/bindings/voidraft/internal/services/dialogservice.ts b/frontend/bindings/voidraft/internal/services/dialogservice.ts new file mode 100644 index 0000000..d6868bd --- /dev/null +++ b/frontend/bindings/voidraft/internal/services/dialogservice.ts @@ -0,0 +1,19 @@ +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * DialogService 对话框服务,处理文件选择等对话框操作 + * @module + */ + +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore: Unused imports +import {Call as $Call, Create as $Create} from "@wailsio/runtime"; + +/** + * SelectDirectory 打开目录选择对话框 + */ +export function SelectDirectory(): Promise & { cancel(): void } { + let $resultPromise = $Call.ByID(2249533621) as any; + return $resultPromise; +} diff --git a/frontend/bindings/voidraft/internal/services/documentservice.ts b/frontend/bindings/voidraft/internal/services/documentservice.ts index bc6c3df..ee530c0 100644 --- a/frontend/bindings/voidraft/internal/services/documentservice.ts +++ b/frontend/bindings/voidraft/internal/services/documentservice.ts @@ -14,10 +14,6 @@ import {Call as $Call, Create as $Create} from "@wailsio/runtime"; // @ts-ignore: Unused imports import * as models$0 from "../models/models.js"; -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore: Unused imports -import * as $models from "./models.js"; - /** * ForceSave 强制保存当前文档 */ @@ -46,30 +42,6 @@ export function GetActiveDocumentContent(): Promise & { cancel(): void } return $resultPromise; } -/** - * GetDiffInfo 获取两个文本之间的详细差异信息 - */ -export function GetDiffInfo(oldText: string, newText: string): Promise<$models.DiffResult> & { cancel(): void } { - let $resultPromise = $Call.ByID(2490726526, oldText, newText) as any; - let $typingPromise = $resultPromise.then(($result: any) => { - return $$createType2($result); - }) as any; - $typingPromise.cancel = $resultPromise.cancel.bind($resultPromise); - return $typingPromise; -} - -/** - * GetSaveSettings 获取文档保存设置 - */ -export function GetSaveSettings(): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(4257471801) as any; - let $typingPromise = $resultPromise.then(($result: any) => { - return $$createType4($result); - }) as any; - $typingPromise.cancel = $resultPromise.cancel.bind($resultPromise); - return $typingPromise; -} - /** * Initialize 初始化文档服务 */ @@ -79,15 +51,7 @@ export function Initialize(): Promise & { cancel(): void } { } /** - * LoadDefaultDocument 加载默认文档 - */ -export function LoadDefaultDocument(): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(2343023569) as any; - return $resultPromise; -} - -/** - * SaveDocumentSync 同步保存文档内容 (用于页面关闭前同步保存) + * SaveDocumentSync 同步保存文档内容 */ export function SaveDocumentSync(content: string): Promise & { cancel(): void } { let $resultPromise = $Call.ByID(3770207288, content) as any; @@ -95,29 +59,13 @@ export function SaveDocumentSync(content: string): Promise & { cancel(): v } /** - * ServiceShutdown 实现应用程序关闭时的服务关闭逻辑 + * ServiceShutdown 服务关闭 */ export function ServiceShutdown(): Promise & { cancel(): void } { let $resultPromise = $Call.ByID(638578044) as any; return $resultPromise; } -/** - * SetSaveCallback 设置保存回调函数 - */ -export function SetSaveCallback(callback: any): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(675315211, callback) as any; - return $resultPromise; -} - -/** - * Shutdown 关闭文档服务,确保所有数据保存 - */ -export function Shutdown(): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(3444504909) as any; - return $resultPromise; -} - /** * UpdateActiveDocumentContent 更新当前活动文档内容 */ @@ -126,17 +74,6 @@ export function UpdateActiveDocumentContent(content: string): Promise & { return $resultPromise; } -/** - * UpdateSaveSettings 更新文档保存设置 - */ -export function UpdateSaveSettings(docConfig: models$0.EditingConfig): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(1245479534, docConfig) as any; - return $resultPromise; -} - // Private type creation functions const $$createType0 = models$0.Document.createFrom; const $$createType1 = $Create.Nullable($$createType0); -const $$createType2 = $models.DiffResult.createFrom; -const $$createType3 = models$0.EditingConfig.createFrom; -const $$createType4 = $Create.Nullable($$createType3); diff --git a/frontend/bindings/voidraft/internal/services/index.ts b/frontend/bindings/voidraft/internal/services/index.ts index 682734b..67cf0c7 100644 --- a/frontend/bindings/voidraft/internal/services/index.ts +++ b/frontend/bindings/voidraft/internal/services/index.ts @@ -2,11 +2,13 @@ // This file is automatically generated. DO NOT EDIT import * as ConfigService from "./configservice.js"; +import * as DialogService from "./dialogservice.js"; import * as DocumentService from "./documentservice.js"; import * as HotkeyService from "./hotkeyservice.js"; import * as SystemService from "./systemservice.js"; export { ConfigService, + DialogService, DocumentService, HotkeyService, SystemService diff --git a/frontend/bindings/voidraft/internal/services/models.ts b/frontend/bindings/voidraft/internal/services/models.ts index b01662a..89c3190 100644 --- a/frontend/bindings/voidraft/internal/services/models.ts +++ b/frontend/bindings/voidraft/internal/services/models.ts @@ -5,137 +5,6 @@ // @ts-ignore: Unused imports import {Create as $Create} from "@wailsio/runtime"; -/** - * DiffResult 包含差异比较的结果信息 - */ -export class DiffResult { - /** - * 编辑操作列表 - */ - "Edits": Edit[]; - - /** - * 插入的字符数 - */ - "InsertCount": number; - - /** - * 删除的字符数 - */ - "DeleteCount": number; - - /** - * 变更的行数 - */ - "ChangedLines": number; - - /** - * 总变更字符数(插入+删除) - */ - "TotalChanges": number; - - /** - * 变更的token数(如单词、标识符等) - */ - "ChangedTokens": number; - - /** Creates a new DiffResult instance. */ - constructor($$source: Partial = {}) { - if (!("Edits" in $$source)) { - this["Edits"] = []; - } - if (!("InsertCount" in $$source)) { - this["InsertCount"] = 0; - } - if (!("DeleteCount" in $$source)) { - this["DeleteCount"] = 0; - } - if (!("ChangedLines" in $$source)) { - this["ChangedLines"] = 0; - } - if (!("TotalChanges" in $$source)) { - this["TotalChanges"] = 0; - } - if (!("ChangedTokens" in $$source)) { - this["ChangedTokens"] = 0; - } - - Object.assign(this, $$source); - } - - /** - * Creates a new DiffResult instance from a string or object. - */ - static createFrom($$source: any = {}): DiffResult { - const $$createField0_0 = $$createType1; - let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; - if ("Edits" in $$parsedSource) { - $$parsedSource["Edits"] = $$createField0_0($$parsedSource["Edits"]); - } - return new DiffResult($$parsedSource as Partial); - } -} - -/** - * Edit 表示单个编辑操作 - */ -export class Edit { - /** - * 操作类型 - */ - "Type": EditType; - - /** - * 操作内容 - */ - "Content": string; - - /** Creates a new Edit instance. */ - constructor($$source: Partial = {}) { - if (!("Type" in $$source)) { - this["Type"] = (0 as EditType); - } - if (!("Content" in $$source)) { - this["Content"] = ""; - } - - Object.assign(this, $$source); - } - - /** - * Creates a new Edit instance from a string or object. - */ - static createFrom($$source: any = {}): Edit { - let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; - return new Edit($$parsedSource as Partial); - } -} - -/** - * Edit 表示编辑操作类型 - */ -export enum EditType { - /** - * The Go zero value for the underlying type of the enum. - */ - $zero = 0, - - /** - * EditInsert 插入操作 - */ - EditInsert = 0, - - /** - * EditDelete 删除操作 - */ - EditDelete = 1, - - /** - * EditEqual 相等部分 - */ - EditEqual = 2, -}; - /** * MemoryStats 内存统计信息 */ @@ -202,7 +71,3 @@ export class MemoryStats { return new MemoryStats($$parsedSource as Partial); } } - -// Private type creation functions -const $$createType0 = Edit.createFrom; -const $$createType1 = $Create.Array($$createType0); diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index eecc66f..d3f34a5 100644 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -73,10 +73,9 @@ export default { selectDirectory: 'Select Directory', selectDataDirectory: 'Select Data Storage Directory', defaultDataPath: 'Default data storage path', - enterCustomPath: 'Enter custom data storage path', - pathHint: 'Example: C:\\MyData or /home/user/data or relative path ./data', bufferFiles: 'Buffer Files Path', useCustomLocation: 'Use custom location for buffer files', + customDataPath: 'Custom Data Storage Path', fontSize: 'Font Size', fontSizeDescription: 'Editor font size', fontSettings: 'Font Settings', @@ -96,7 +95,6 @@ export default { restartRequired: '(Restart required)', saveOptions: 'Save Options', autoSaveDelay: 'Auto Save Delay (ms)', - changeThreshold: 'Change Threshold', - minSaveInterval: 'Min Save Interval (ms)' + selectDirectoryFailed: 'Failed to select directory' } }; \ No newline at end of file diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 0982365..1603e81 100644 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -73,10 +73,9 @@ export default { selectDirectory: '选择目录', selectDataDirectory: '选择数据存储目录', defaultDataPath: '默认数据存储路径', - enterCustomPath: '请输入自定义数据存储路径', - pathHint: '例如: C:\\MyData 或 /home/user/data 或相对路径 ./data', bufferFiles: '缓冲文件路径', useCustomLocation: '使用自定义位置存储缓冲文件', + customDataPath: '自定义数据存储路径', fontSize: '字体大小', fontSizeDescription: '编辑器字体大小', fontSettings: '字体设置', @@ -96,7 +95,6 @@ export default { restartRequired: '(需要重启)', saveOptions: '保存选项', autoSaveDelay: '自动保存延迟(毫秒)', - changeThreshold: '变更字符阈值', - minSaveInterval: '最小保存间隔(毫秒)' + selectDirectoryFailed: '选择目录失败' } }; \ No newline at end of file diff --git a/frontend/src/stores/configStore.ts b/frontend/src/stores/configStore.ts index 5b3de69..afd3945 100644 --- a/frontend/src/stores/configStore.ts +++ b/frontend/src/stores/configStore.ts @@ -62,9 +62,7 @@ const EDITING_CONFIG_KEY_MAP: EditingConfigKeyMap = { enableTabIndent: 'editing.enable_tab_indent', tabSize: 'editing.tab_size', tabType: 'editing.tab_type', - autoSaveDelay: 'editing.auto_save_delay', - changeThreshold: 'editing.change_threshold', - minSaveInterval: 'editing.min_save_interval' + autoSaveDelay: 'editing.auto_save_delay' } as const; const APPEARANCE_CONFIG_KEY_MAP: AppearanceConfigKeyMap = { @@ -137,9 +135,7 @@ const DEFAULT_CONFIG: AppConfig = { enableTabIndent: true, tabSize: CONFIG_LIMITS.tabSize.default, tabType: CONFIG_LIMITS.tabType.default, - autoSaveDelay: 5000, - changeThreshold: 500, - minSaveInterval: 1000 + autoSaveDelay: 5000 }, appearance: { language: LanguageType.LangZhCN @@ -338,9 +334,7 @@ export const useConfigStore = defineStore('config', () => { fontFamily: (value: string) => safeCall(() => updateEditingConfig('fontFamily', value), 'config.saveFailed', 'config.saveSuccess'), fontWeight: (value: string) => safeCall(() => updateEditingConfig('fontWeight', value), 'config.saveFailed', 'config.saveSuccess'), defaultDataPath: (value: string) => safeCall(() => updateGeneralConfig('defaultDataPath', value), 'config.saveFailed', 'config.saveSuccess'), - autoSaveDelay: (value: number) => safeCall(() => updateEditingConfig('autoSaveDelay', value), 'config.saveFailed', 'config.saveSuccess'), - changeThreshold: (value: number) => safeCall(() => updateEditingConfig('changeThreshold', value), 'config.saveFailed', 'config.saveSuccess'), - minSaveInterval: (value: number) => safeCall(() => updateEditingConfig('minSaveInterval', value), 'config.saveFailed', 'config.saveSuccess') + autoSaveDelay: (value: number) => safeCall(() => updateEditingConfig('autoSaveDelay', value), 'config.saveFailed', 'config.saveSuccess') }; return { @@ -394,8 +388,6 @@ export const useConfigStore = defineStore('config', () => { // 保存配置相关方法 setAutoSaveDelay: setters.autoSaveDelay, - setChangeThreshold: setters.changeThreshold, - setMinSaveInterval: setters.minSaveInterval, // 热键配置相关方法 setEnableGlobalHotkey: (value: boolean) => safeCall(() => updateGeneralConfig('enableGlobalHotkey', value), 'config.saveFailed', 'config.saveSuccess'), diff --git a/frontend/src/views/editor/extensions/autoSaveExtension.ts b/frontend/src/views/editor/extensions/autoSaveExtension.ts index c40acba..803e9a7 100644 --- a/frontend/src/views/editor/extensions/autoSaveExtension.ts +++ b/frontend/src/views/editor/extensions/autoSaveExtension.ts @@ -12,6 +12,12 @@ export interface AutoSaveOptions { /** * 创建自动保存插件 + * + * 新的简化保存策略: + * - 前端只负责将内容变更传递给后端 + * - 后端使用定时保存机制,每隔配置的时间间隔自动保存(仅在有变更时) + * - 移除了复杂的阈值保存和最小间隔控制 + * * @param options 配置选项 * @returns EditorView.Plugin */ diff --git a/frontend/src/views/settings/pages/EditingPage.vue b/frontend/src/views/settings/pages/EditingPage.vue index 576f63c..8b672f8 100644 --- a/frontend/src/views/settings/pages/EditingPage.vue +++ b/frontend/src/views/settings/pages/EditingPage.vue @@ -138,27 +138,31 @@ const handleAutoSaveDelayChange = async (event: Event) => { } }; -const handleChangeThresholdChange = async (event: Event) => { - const target = event.target as HTMLInputElement; - const value = parseInt(target.value, 10); - if (!isNaN(value) && value >= 10 && value <= 10000) { - await safeCall( - () => configStore.setChangeThreshold(value), - 'config.changeThresholdUpdateFailed' - ); +// 动态字体预览文本 +const fontPreviewText = computed(() => { + const currentFont = configStore.config.editing.fontFamily; + + // 根据字体类型返回不同的预览文本 + if (currentFont.includes('HarmonyOS')) { + return '鸿蒙字体测试'; + } else if (currentFont.includes('Microsoft YaHei')) { + return '微软雅黑测试'; + } else if (currentFont.includes('PingFang')) { + return '苹方字体测试'; + } else if (currentFont.includes('JetBrains')) { + return 'JetBrains Mono'; + } else if (currentFont.includes('Fira Code')) { + return 'Fira Code Test'; + } else if (currentFont.includes('Source Code')) { + return 'Source Code Pro'; + } else if (currentFont.includes('Cascadia')) { + return 'Cascadia Code'; + } else if (currentFont.includes('SF Mono') || currentFont.includes('Monaco')) { + return 'System Monospace'; + } else { + return 'Font Preview'; } -}; - -const handleMinSaveIntervalChange = async (event: Event) => { - const target = event.target as HTMLInputElement; - const value = parseInt(target.value, 10); - if (!isNaN(value) && value >= 100 && value <= 10000) { - await safeCall( - () => configStore.setMinSaveInterval(value), - 'config.minSaveIntervalUpdateFailed' - ); - } -}; +}); diff --git a/frontend/src/views/settings/pages/GeneralPage.vue b/frontend/src/views/settings/pages/GeneralPage.vue index 5213290..952ac18 100644 --- a/frontend/src/views/settings/pages/GeneralPage.vue +++ b/frontend/src/views/settings/pages/GeneralPage.vue @@ -1,11 +1,12 @@