From 627c3dc71faa6787d29018937270b51a0fb9222f Mon Sep 17 00:00:00 2001 From: landaiqing Date: Sun, 16 Nov 2025 15:16:49 +0800 Subject: [PATCH] :bug: Fixed markdown preview issue --- frontend/src/stores/editorStore.ts | 5 ++++ .../extensions/markdownPreview/panel.ts | 23 ++----------------- internal/common/constant/constant.go | 3 ++- internal/services/window_helper.go | 2 +- main.go | 8 +++---- 5 files changed, 14 insertions(+), 27 deletions(-) diff --git a/frontend/src/stores/editorStore.ts b/frontend/src/stores/editorStore.ts index 9366207..b3fd40b 100644 --- a/frontend/src/stores/editorStore.ts +++ b/frontend/src/stores/editorStore.ts @@ -4,6 +4,7 @@ import {EditorView} from '@codemirror/view'; import {EditorState, Extension} from '@codemirror/state'; import {useConfigStore} from './configStore'; import {useDocumentStore} from './documentStore'; +import {usePanelStore} from './panelStore'; import {ExtensionID} from '@/../bindings/voidraft/internal/models/models'; import {DocumentService, ExtensionService} from '@/../bindings/voidraft/internal/services'; import {ensureSyntaxTree} from "@codemirror/language"; @@ -685,6 +686,10 @@ export const useEditorStore = defineStore('editor', () => { // 销毁编辑器 instance.view.destroy(); }); + + // 清理 panelStore 状态(导航离开编辑器页面时) + const panelStore = usePanelStore(); + panelStore.reset(); currentEditor.value = null; }; diff --git a/frontend/src/views/editor/extensions/markdownPreview/panel.ts b/frontend/src/views/editor/extensions/markdownPreview/panel.ts index e1d173f..125b44b 100644 --- a/frontend/src/views/editor/extensions/markdownPreview/panel.ts +++ b/frontend/src/views/editor/extensions/markdownPreview/panel.ts @@ -6,9 +6,6 @@ import MarkdownIt from 'markdown-it'; import * as runtime from "@wailsio/runtime"; import {previewPanelState} from "./state"; import {createMarkdownRenderer} from "./markdownRenderer"; -import {updateMermaidTheme} from "@/common/markdown-it/plugins/markdown-it-mermaid"; -import {useThemeStore} from "@/stores/themeStore"; -import {watch} from "vue"; import {createDebounce} from "@/common/utils/debounce"; import {morphHTML} from "@/common/utils/domDiff"; @@ -21,9 +18,8 @@ export class MarkdownPreviewPanel { private readonly resizeHandle: HTMLDivElement; private readonly content: HTMLDivElement; private view: EditorView; - private themeUnwatch?: () => void; private lastRenderedContent: string = ""; - private debouncedUpdate: ReturnType; + private readonly debouncedUpdate: ReturnType; private isDestroyed: boolean = false; // 标记面板是否已销毁 constructor(view: EditorView) { @@ -33,16 +29,7 @@ export class MarkdownPreviewPanel { // 创建防抖更新函数 this.debouncedUpdate = createDebounce(() => { this.updateContentInternal(); - }, { delay: 1000 }); - - // 监听主题变化 - const themeStore = useThemeStore(); - this.themeUnwatch = watch(() => themeStore.isDarkMode, (isDark) => { - const newTheme = isDark ? "dark" : "default"; - updateMermaidTheme(newTheme); - this.lastRenderedContent = ""; // 清空缓存,强制重新渲染 - this.updateContentInternal(); - }); + }, { delay: 500 }); // 创建 DOM 结构 this.dom = document.createElement("div"); @@ -340,12 +327,6 @@ export class MarkdownPreviewPanel { this.debouncedUpdate.cancel(); } - // 清理主题监听 - if (this.themeUnwatch) { - this.themeUnwatch(); - this.themeUnwatch = undefined; - } - // 清空缓存 this.lastRenderedContent = ""; } diff --git a/internal/common/constant/constant.go b/internal/common/constant/constant.go index 344236a..45e30c8 100644 --- a/internal/common/constant/constant.go +++ b/internal/common/constant/constant.go @@ -3,7 +3,8 @@ package constant // VOIDRAFT_MAIN_WINDOW_NAME is the name of the main window of the Voidcraft client. const VOIDRAFT_MAIN_WINDOW_NAME = "voidraft-main-window" -const VOIDRAFT_WINDOW_TITLE = "voidraft" +const VOIDRAFT_APP_NAME = "voidraft" +const VOIDRAFT_APP_DESCRIPTION = "An elegant text snippet recording tool designed for developers." const VOIDRAFT_WINDOW_WIDTH = 700 diff --git a/internal/services/window_helper.go b/internal/services/window_helper.go index 54e97e9..b7ae2b1 100644 --- a/internal/services/window_helper.go +++ b/internal/services/window_helper.go @@ -74,7 +74,7 @@ func (wh *WindowHelper) FocusMainWindow() bool { func (wh *WindowHelper) AutoShowMainWindow() { window := wh.MustGetMainWindow() if window.IsVisible() { - window.Hide() + window.Focus() } else { window.Show() } diff --git a/main.go b/main.go index e406930..6c68fa9 100644 --- a/main.go +++ b/main.go @@ -39,8 +39,8 @@ func main() { // 'Bind' is a list of Go struct instances. The frontend has access to the methods of these instances. // 'Mac' options tailor the application when running an macOS. app := application.New(application.Options{ - Name: "voidraft", - Description: "voidraft", + Name: constant.VOIDRAFT_APP_NAME, + Description: constant.VOIDRAFT_APP_DESCRIPTION, Services: serviceManager.GetServices(), Assets: application.AssetOptions{ Handler: application.AssetFileServerFS(assets), @@ -50,7 +50,7 @@ func main() { ApplicationShouldTerminateAfterLastWindowClosed: true, }, SingleInstance: &application.SingleInstanceOptions{ - UniqueID: "com.voidraft", + UniqueID: constant.VOIDRAFT_APP_NAME, EncryptionKey: encryptionKey, OnSecondInstanceLaunch: func(data application.SecondInstanceData) { if window != nil { @@ -71,7 +71,7 @@ func main() { // 'URL' is the URL that will be loaded into the webview. mainWindow := app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: constant.VOIDRAFT_MAIN_WINDOW_NAME, - Title: constant.VOIDRAFT_WINDOW_TITLE, + Title: constant.VOIDRAFT_APP_NAME, Width: constant.VOIDRAFT_WINDOW_WIDTH, Height: constant.VOIDRAFT_WINDOW_HEIGHT, Hidden: false,