Skip to content

MDeX-2.2.0

Choose a tag to compare

@fwzheng fwzheng released this 03 Aug 15:29

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_atmove_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 to std::fs without scope validation. Added assert_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 viewer innerHTML sinks using DOMPurify (svg+html profile + foreignObject allowance), stripping <script>, on* handlers, and javascript: protocols.
  • 收紧 Opener 权限
    Capabilities 配置项 opener:default 收缩为显式的 allow-open-url + allow-default-urls 权限,并移除了未使用的 allow-reveal-item-in-dir 权限,遵循最小权限原则。
    Tightened opener capability: Replaced opener:default with explicit allow-open-url + allow-default-urls scopes and removed the unused allow-reveal-item-in-dir permission.

性能 / 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-platform cargo test + e2e alignment). Fixed test-align-e2e.mjs exit 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 where init/loadTab did not reset the undo baseline to the loaded content, causing Ctrl+Z to restore an empty state. Added commitUndo(prev) to capture the real pre-edit snapshot inline and resetUndo after 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. selectMatch now uses measured visual-line Y coordinates instead of logical-line calculations.
  • 界面显示异常
    • 替换栏显示问题:修复仅查找模式下替换栏不隐藏的问题(原因:.search-rowdisplay:flex 覆盖了 [hidden] 属性),补充了高特异性 CSS 规则。
      Replace row visibility: Fixed an issue where the replace row remained visible in find-only mode (display:flex was overriding [hidden]).
    • AI 弹窗状态异常:修复 AI 弹窗 display:flex 覆盖 [hidden] 导致无法关闭及启动时残留弹窗的问题,增加 #ai-pop[hidden] 规则。
      AI pane visibility: Fixed a bug where display:flex prevented 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.