Files
md-preview/agent/docs/roadmap.md
Richard Wu 1e8cbea902 feat: zoom content with Ctrl+wheel (5% step, 50-300%)
- Ctrl+wheel zooms preview and editor; 90ms throttle; preventDefault stops WebView2 page zoom
- Range widened to 50-300%, step unified at 5% for wheel, toolbar buttons and Ctrl +/-
- No mouse-anchor (same scrolling behavior as button zoom)
- Add agent/AGENTS.md: workspace boundary is the top rule; build/test temp dirs stay in target/
- build.ps1 redirects TEMP/TMP into target/tmp
2026-10-21 16:23:00 +08:00

100 lines
4.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 功能路线图 — 2026-10-21 决策版
## 决策(已确认)
- 缩放:**Ctrl + 鼠标滚轮**;右键菜单保持禁用。
- 移除右上角 Open / Print 按钮;保留 `Ctrl+O` / `Ctrl+P` 与空状态 Open。
- 按 `#` 层级折叠标题,方便读长文。
- 代码配色改为 Visual Studio 风格;只换 hljs CSS,不引入新库。
- 整体原则:轻量,不引库,不加联网能力。
## 顺序与预估
| 步骤 | 内容 | 预估 | 风险 |
|---|---|---|---|
| 0 | git + agent 骨架(本次已完成除 git 外的准备) | 0.5–1 h | 低 |
| 1 | Bug 修复批:`\\?\` / base href / 非 md 链接 / session 兜底 | 2–3 h | 低 |
| 2 | 移除 Open / Print 按钮 | 0.5 h | 低 |
| 3 | 代码配色 VS 风格 | 1.5–2.5 h | 低 |
| 4 | Ctrl + 滚轮缩放 | 0.5–1 h | 低 |
| 5 | 标题折叠 | 6–10 h | 中高 |
| 6 | 回归(大文档、多标签、mermaid、打印) | 2–3 h | 中 |
轻量版约 1 天;稳妥版(折叠完整、含回归)约 2.5–3.5 天。
## 步骤 2:移除 Open / Print
改动点:
- HTML:`src/main.rs:1350`(Open)、`1353`(Print)
- CSS:`src/main.rs:1333-1335` 的 `body.editing #btn-open, #btn-search, #btn-print`
- JS:`ICON_OPEN` / `ICON_PRINT`、`btnOpen` / `btnPrint`、两个 click 监听
- Strings:`btn_print`;`btn_open`(空状态用的是 `open_file`,不再需要)
- 测试:`src/main.rs:2293`、`2302`
保留:`Ctrl+O`、`Ctrl+P`、`window.__mdPreviewOpenFile`(脏标签时 Rust 回调用)。
验收:工具栏只剩 搜索 / 编辑 / 缩放;`Ctrl+O`、`Ctrl+P`、空状态 Open、Recent 均正常;`cargo test` 全绿。
## 步骤 3:代码配色(Visual Studio 风格)
- 新增 `assets/hljs/vs2015.min.css`(深色)与 `vs.min.css` 或 `atom-one-light.min.css`(浅色),替换现有 GitHub 主题。
- 同步调整 `#preview pre` 背景:浅色 `#f6f8fa` 或 `#fff`,深色 `#1e1e1e`。
- 不改 JS,不加库;仍由 `prefers-color-scheme` 切换。
- 用 `tests/fixtures/code-samples.md` 目测 C# / Rust / JS / JSON / YAML / PowerShell / diff 的对比度。
验收:浅色/深色都不刺眼;字符串、注释、关键字、类型、数字有明显区分;代码块背景与主题一致。
可选:加“代码配色”独立切换(localStorage),+2–3 h。
## 步骤 4:Ctrl + 滚轮
实现要点(已按确认调整):
- `window.addEventListener('wheel', handler, { passive: false })`。
- 只有 `e.ctrlKey` 时 `preventDefault()`,避免 WebView2 自己的页面缩放。
- 复用 `changeZoom(±ZOOM_STEP)`;`deltaY` 方向 + 90ms 节流。
- 步进统一为 **5%**(滚轮、工具栏按钮、`Ctrl +/-` 一致)。
- 范围 **50%–300%**;`Ctrl+0` 复位 100%。
- 不做鼠标位置锚点(与现有按钮缩放行为一致,滚动位置保持)。
- 触控板双指捏合在 Chromium 里也表现为 `ctrlKey + wheel`,顺带支持。
- 编辑模式下同样生效(`--content-scale` 已作用于 textarea)。
验收:预览/编辑都能缩放;范围 50%–300%;Ctrl+0 复位;不触发浏览器缩放;不按 Ctrl 时滚动不受影响。
## 步骤 5:标题折叠
实现要点:
1. 在 `preview-enhance.js` 里,把 `#preview` 的标题按层级包成嵌套 `<section class="mdp-fold" data-level="n">`。
2. 标题左侧加三角按钮(`<button class="mdp-fold-toggle" aria-expanded>`),点击切换 `collapsed`。
3. **状态持久化**:`localStorage` 按 `tabKey(文件路径)+ heading id` 存折叠集合;Rust 需把 tab 路径传给页面(`__setContent` 多一个参数,或复用 `__setTabs` 的 active path)。
4. 每次 `__setPreview` 重建 DOM 后立即恢复折叠态(在 idle enhance 之前),避免闪烁。
5. 查找:命中在折叠区时自动展开祖先(或先展开全部再恢复,二选一,需实测体验)。
6. Mermaid:隐藏容器里尺寸为 0,展开后需要重新渲染/触发布局;建议记录源码,展开时重跑。
7. 打印:`@media print` 强制展开,避免打印缺失内容。
8. 可选:`Alt+点击` 折叠整棵子树;“全部折叠/展开”快捷键。
验收:
- 点击 H1/H2/H3 三角可折叠其正文与子标题;
- 自动保存 700ms 后折叠状态不丢;
- 切换标签后各自的折叠状态正确;
- 查找、锚点跳转、打印、mermaid 均正常;
- 大文档(>= 1MB)折叠后滚动与展开无明显卡顿。
## 回归清单(每次发版)
- [ ] 窗口标题 `文件名 — MD Preview`,脏状态显示 `•`
- [ ] 工具栏无 Open / Print
- [ ] 多标签、关闭、会话恢复、缺失文件重定位
- [ ] 编辑 700ms 自动保存;关闭前落盘
- [ ] 外部修改提示与保护
- [ ] 查找(含中文输入法组合输入)
- [ ] Ctrl+滚轮、Ctrl+0、50%–300%
- [ ] 折叠状态与自动保存共存
- [ ] 代码配色浅/深
- [ ] 打印预览完整
- [ ] 单实例转发
- [ ] `agent/scripts/build.ps1` 通过,exe 为 Medium