MDeX-2.2.0
v2.2.0
本次更新重点: 安全加固、性能优化、AI 辅助弹窗改版,以及多项 Bug 修复(重点解决了一项可能导致“撤销清空文档”的数据丢失隐患)。
Highlights: Security hardening, performance optimizations, an AI-pane redesign, and numerous bug fixes (including a critical data-loss bug where undo could clear the document).
安全 / Security
- 自定义文件系统命令增加路径校验:
先前有 7 个自定义 Tauri 命令(如write_bytes_at、move_dir等)直接将前端传入的路径传递给std::fs,缺乏作用域校验。本次更新新增了assert_safe_path校验逻辑(包含路径规范化、..折叠处理及敏感目录黑名单机制,如~/.ssh、~/.aws、/etc等)。此举将潜在的 Webview 脚本注入攻击半径从“全用户文件系统”有效收窄至“非敏感路径”。
Path-scope guard on custom FS commands: Previously, 7 custom Tauri commands passed front-end paths directly tostd::fswithout scope validation. Addedassert_safe_path(canonicalization +..collapse + sensitive-directory denylist) to restrict hypothetical webview script-injection attacks from accessing secrets/persistence/system directories. - SVG 注入点净化:
针对 Mermaid 及图片查看器的innerHTML注入点,统一接入 DOMPurify 进行净化(采用svg+html配置并放行foreignObject),有效剥离<script>标签、on*事件属性及javascript:协议,防止 XSS 攻击。
SVG sanitization at injection points: Unified sanitization for viewerinnerHTMLsinks using DOMPurify (svg+htmlprofile +foreignObjectallowance), stripping<script>,on*handlers, andjavascript:protocols. - 收紧 Opener 权限:
Capabilities 配置项opener:default收缩为显式的allow-open-url+allow-default-urls权限,并移除了未使用的allow-reveal-item-in-dir权限,遵循最小权限原则。
Tightened opener capability: Replacedopener:defaultwith explicitallow-open-url+allow-default-urlsscopes and removed the unusedallow-reveal-item-in-dirpermission.
性能 / Performance
- 渲染优化:
renderIntoPreview针对非虚拟分支复用已解析的模板(cloneNode),避免了二次innerHTML解析带来的性能开销。 - 网络与内存优化:实现
reqwest::Client进程级复用,节省了每次 AI 请求的 DNS/TCP/TLS 握手开销;优化drain_complete_lines算法,改用游标实现,消除 O(n²) 复杂度的 memmove 操作;read_image_data_url采用 String 预分配策略,减少内存拷贝次数。 - 构建与交互优化:
build-html.mjs改为并行读取 vendor 文件;搜索输入增加 debounce(防抖)处理;优化撤销快照缓存策略,确保editor.value仅缓存一次。
新增 / Features
- AI 辅助弹窗改版:
移除顶部冗余头部行;编辑区标签现显示当前 AI 名称;将用户输入与 AI 回答合并为单一对话框,交互更连贯;发送按钮移入输入行;关闭按钮(×)置于编辑区标签行(纯问答模式亦显示该行);弹窗右下角新增拖拽调整大小功能。
AI pane redesign: Removed the redundant header row. The edit-zone label now displays the active AI name. User input and AI replies are merged into a unified dialog flow. The send button moved into the input row, and the close button (×) sits in the edit-zone label row (visible in chat-only mode as well). The pane is now resizable via a bottom-right handle. - LaTeX 导出 Golden 测试:
tools/test-pure.mjs升级为具备字符串/正则/注释感知能力的函数提取器,新增texInline/texColor/detectTexLangs等 16 条断言(测试覆盖从 20 提升至 36 条)。
LaTeX export golden tests: Upgraded the extractor with string/regex/comment awareness, adding 16 new assertions (total coverage increased from 20 to 36 cases). - CI 流程完善:
新增.github/workflows/ci.yml,包含 Web 护栏检查、跨平台cargo test及 e2e 对齐测试;修复test-align-e2e.mjs退出码逻辑(此前断言失败错误地返回了 exit 0)。
CI workflow: Added.github/workflows/ci.yml(web lint + cross-platformcargo test+ e2e alignment). Fixedtest-align-e2e.mjsexit code logic (previously returned exit 0 on assertion failures).
修复 / Fixes
- 撤销操作导致文档清空(数据丢失隐患):
修复init/loadTab加载文档时未重置undoLast基线的问题。此前,程序化编辑入栈后执行 Ctrl+Z 会错误地将文档恢复为空内容。现已新增commitUndo(prev)函数,利用“编辑前快照”入栈(不再依赖可能过时的全局undoLast),并在文档加载后调用resetUndo。同时修复了 Ctrl+K 插链接等工具栏格式化操作不可撤销的问题。
Undo could clear the document (data loss): Fixed a bug whereinit/loadTabdid not reset the undo baseline to the loaded content, causing Ctrl+Z to restore an empty state. AddedcommitUndo(prev)to capture the real pre-edit snapshot inline andresetUndoafter load. Also made toolbar formatting actions (Ctrl+K link, bold, etc.) properly undoable. - 搜索功能体验优化:
修复搜索“下一个”匹配项时,非首条匹配项未能居中或高亮的问题。selectMatch改用offToEditorY(基于实测视觉行 Y 坐标),替代原先逻辑行乘以硬编码行高的计算方式。
Search "next" match centering/highlighting: Fixed an issue where non-first matches were not centered/highlighted.selectMatchnow uses measured visual-line Y coordinates instead of logical-line calculations. - 界面显示异常:
- 替换栏显示问题:修复仅查找模式下替换栏不隐藏的问题(原因:
.search-row的display:flex覆盖了[hidden]属性),补充了高特异性 CSS 规则。
Replace row visibility: Fixed an issue where the replace row remained visible in find-only mode (display:flexwas overriding[hidden]). - AI 弹窗状态异常:修复 AI 弹窗
display:flex覆盖[hidden]导致无法关闭及启动时残留弹窗的问题,增加#ai-pop[hidden]规则。
AI pane visibility: Fixed a bug wheredisplay:flexprevented the AI pane from closing or caused stray popups on startup. - 菜单响应失效:修复点击「MDeX简介」无反应的问题(原因:
HELP_STRINGS声明代码意外粘合至注释行)。
"MDeX intro" menu item: Fixed unresponsiveness caused by code being incorrectly concatenated into a comment line.
- 替换栏显示问题:修复仅查找模式下替换栏不隐藏的问题(原因:
- 文案优化:
AI 设置标题由「AI 辅助设置」精简为「AI 设置」(17 种语言统一更新);精简输入框 placeholder 中冗长的括号说明。
UI Text: Shortened AI-settings title across 17 languages and simplified input placeholder text. - 版本号升级:
版本号更新至 2.2.0。
Version bumped to 2.2.0.