v0.3.5: Bug修复+性能优化+状态栏文档统计

Bug修复:
- BUG-01: Sidebar norm函数正则修复(单反斜杠匹配), Windows路径规范化恢复
- BUG-02: 3处result.content truthy检查改为content !== undefined, 空文件可打开
- BUG-03: TAB_SWITCHED路径校验顺序修复, activeFilePath不在校验前写入

优化:
- OPT-01: Sidebar handleFileClick添加loading状态, 打开文件有视觉反馈

新功能:
- FEAT-01: 状态栏添加行数/单词数/字符数统计
  - useDocStats hook + computeDocStats 纯函数
  - StatusBar右侧显示 行/词/字符 统计信息
  - 12个单元测试覆盖空值/空白/ASCII/UTF-8/Markdown等场景

验证: TS 0错误, ESLint 0错误(1个预存警告), 90/90测试通过
This commit is contained in:
thzxx
2026-06-04 13:43:10 +08:00
parent 899d2b7914
commit a84ccb7353
9 changed files with 157 additions and 13 deletions
+39
View File
@@ -0,0 +1,39 @@
import { useMemo } from 'react'
export interface DocStats {
/** 单词数(按空白字符分割) */
words: number
/** 总字符数(含空白字符) */
chars: number
/** 字符数(不含空白字符) */
charsNoSpace: number
/** 行数 */
lines: number
}
/**
* 计算文档统计信息:单词数、字符数(含/不含空格)、行数。
* 对空文档或 undefined 返回全零值。
*/
export function computeDocStats(content: string | undefined | null): DocStats {
if (!content) {
return { words: 0, chars: 0, charsNoSpace: 0, lines: 0 }
}
const chars = content.length
const charsNoSpace = content.replace(/\s/g, '').length
const words = content.trim()
? content.trim().split(/\s+/).length
: 0
const lines = content === '' ? 0 : content.split(/\r?\n/).length
return { words, chars, charsNoSpace, lines }
}
/**
* Hook:根据文档内容实时计算统计信息。
* 使用 useMemo 避免不必要的重新计算。
*/
export function useDocStats(content: string | undefined | null): DocStats {
return useMemo(() => computeDocStats(content), [content])
}