diff --git a/build/linux/appimage/appicon.png b/build/linux/appimage/appicon.png new file mode 100644 index 0000000..613d223 Binary files /dev/null and b/build/linux/appimage/appicon.png differ diff --git a/build/linux/voidraft.desktop b/build/linux/voidraft.desktop new file mode 100644 index 0000000..680f1db --- /dev/null +++ b/build/linux/voidraft.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Type=Application +Name=voidraft +Exec=voidraft +Icon=appicon +Categories=Development; +Terminal=false +Keywords=wails +Version=1.0 +StartupNotify=false diff --git a/frontend/src/stores/editorStore.ts b/frontend/src/stores/editorStore.ts index 44d6bd6..d4dc165 100644 --- a/frontend/src/stores/editorStore.ts +++ b/frontend/src/stores/editorStore.ts @@ -9,7 +9,6 @@ import {createBasicSetup} from '@/views/editor/extensions/basicSetup'; import { createStatsUpdateExtension, getTabExtensions, - updateStats, updateTabConfig, createAutoSavePlugin, createSaveShortcutPlugin, @@ -22,7 +21,7 @@ import { useThemeStore } from './themeStore'; import { useI18n } from 'vue-i18n'; import { SystemThemeType } from '@/../bindings/voidraft/internal/models/models'; import { DocumentService } from '@/../bindings/voidraft/internal/services'; - +import {ensureSyntaxTree } from "@codemirror/language" export interface DocumentStats { lines: number; characters: number; @@ -199,15 +198,15 @@ export const useEditorStore = defineStore('editor', () => { // 将编辑器实例保存到store setEditorView(view); + isEditorInitialized.value = true; - // 确保编辑器已渲染后再滚动到底部 scrollToBottom(view); + + ensureSyntaxTree(view.state, view.state.doc.length, 5000) + // 应用初始字体大小 applyFontSize(); - - // 立即更新统计信息 - updateStats(view, updateDocumentStats); }; // 重新配置编辑器 diff --git a/frontend/src/views/editor/extensions/statsExtension.ts b/frontend/src/views/editor/extensions/statsExtension.ts index a7db4f0..429ae1a 100644 --- a/frontend/src/views/editor/extensions/statsExtension.ts +++ b/frontend/src/views/editor/extensions/statsExtension.ts @@ -1,6 +1,8 @@ import {Extension} from '@codemirror/state'; import {EditorView} from '@codemirror/view'; import {DocumentStats} from '@/stores/editorStore'; +import {getActiveNoteBlock} from '@/views/editor/extensions/codeblock/state'; + // 更新编辑器文档统计信息 export const updateStats = ( view: EditorView, @@ -9,22 +11,44 @@ export const updateStats = ( if (!view) return; const state = view.state; - const doc = state.doc; - const text = doc.toString(); - // 计算选中的字符数 + // 获取当前光标所在的代码块 + const activeBlock = getActiveNoteBlock(state as any); + + if (!activeBlock) { + // 如果没有活动块,显示空统计 + updateDocumentStats({ + lines: 0, + characters: 0, + selectedCharacters: 0 + }); + return; + } + + // 获取当前块的内容范围 + const blockContent = state.doc.sliceString(activeBlock.content.from, activeBlock.content.to); + + // 计算块内容的行数 + const blockLines = blockContent.split('\n').length; + + // 计算选中的字符数(只统计在当前块内的选中内容) let selectedChars = 0; const selections = state.selection; if (selections) { for (let i = 0; i < selections.ranges.length; i++) { const range = selections.ranges[i]; - selectedChars += range.to - range.from; + // 计算选中范围与当前块内容范围的交集 + const selectionStart = Math.max(range.from, activeBlock.content.from); + const selectionEnd = Math.min(range.to, activeBlock.content.to); + if (selectionStart < selectionEnd) { + selectedChars += selectionEnd - selectionStart; + } } } updateDocumentStats({ - lines: doc.lines, - characters: text.length, + lines: blockLines, + characters: blockContent.length, selectedCharacters: selectedChars }); }; diff --git a/internal/models/config.go b/internal/models/config.go index 35366de..3d6e04b 100644 --- a/internal/models/config.go +++ b/internal/models/config.go @@ -1,8 +1,6 @@ package models import ( - "os" - "path/filepath" "time" ) @@ -103,19 +101,10 @@ type ConfigMetadata struct { // NewDefaultAppConfig 创建默认应用配置 func NewDefaultAppConfig() *AppConfig { - // 获取当前工作目录 - currentDir, err := os.Getwd() - if err != nil { - currentDir = "." - } - - // 默认路径配置 - 使用当前目录 - dataDir := filepath.Join(currentDir, "data") - return &AppConfig{ General: GeneralConfig{ AlwaysOnTop: false, - DataPath: dataDir, + DataPath: "./data", EnableSystemTray: true, StartAtLogin: false, EnableGlobalHotkey: false, diff --git a/internal/models/document.go b/internal/models/document.go index 0d1306b..99569af 100644 --- a/internal/models/document.go +++ b/internal/models/document.go @@ -36,6 +36,6 @@ func NewDefaultDocument() *Document { LastUpdated: now, CreatedAt: now, }, - Content: "\n∞∞∞text-a\n", + Content: "∞∞∞text-a\n", } } diff --git a/internal/services/startup_linux.go b/internal/services/startup_linux.go index c51fe9b..6268645 100644 --- a/internal/services/startup_linux.go +++ b/internal/services/startup_linux.go @@ -6,7 +6,6 @@ import ( "fmt" "os" "path/filepath" - "strings" "text/template" "github.com/wailsapp/wails/v3/pkg/services/log"