docs: record the CodeMirror 5 editor work
This commit is contained in:
@@ -218,17 +218,22 @@ cargo test
|
||||
- 架构拆分阶段 4(功能不变,2026-11-06,`fb10fc5`):新增 `src/app.rs`(`UserEvent`/`WindowState`/`AppState`、渲染、`build_webview`、窗口创建/关闭、`run_event_loop`);`main.rs` 只留 CLI、启动装配、`main()` 和测试(2365 → 804 行)。60 tests 全绿,clippy/fmt 干净,release 仍是 5,502,464 字节。
|
||||
- 架构拆分阶段 5(功能不变,2026-11-06,`a5c0b08`):测试全部随模块迁移(app 7、markdown 23、page 5、config 2、files 10、session 10、instance 3,共 60),共享 `testutil::temp_dir`;启动装配与 CLI 移入 `app::run()`,`main.rs` 18 行(仅模块声明 + `app::run()`)。
|
||||
- HKCU 关联:应用启动时不再写注册表(`register_as_default` 及 `winreg` 依赖已删除);`publish.ps1` 维持现状(继续写 ProgID/关联)。首次使用需在 Windows“打开方式 → 选择其他应用”里选一次。
|
||||
- 白屏 bug(2026-11-04 修复):`render_active_document` 给 `window.__setContent` 传了 8 个参数,页面签名只有 7 个(多传了 `active.id`),标签 id 被当成 `previewHtml` 渲染——窗口白屏、打开标签依次显示 1/2/3/4。修复:抽出 `set_content_script()`(单一参数源),新增精确输出 + 页面签名对照测试 `set_content_script_matches_the_page_signature`(60 tests)。教训:Rust→JS 这条边界没有编译器检查。
|
||||
- 白屏 bug(2026-11-04 修复):当时 `render_active_document` 给 `window.__setContent` 传了 8 个参数,页面签名只有 7 个(多传了 `active.id`),标签 id 被当成 `previewHtml` 渲染——窗口白屏、打开标签依次显示 1/2/3/4。修复:抽出 `set_content_script()`(单一参数源),新增精确输出 + 页面签名对照测试 `set_content_script_matches_the_page_signature`(60 tests)。教训:Rust→JS 这条边界没有编译器检查。
|
||||
- 发布前 UI 冒烟:`agent/tests/ui-smoke.cmd`(普通桌面 PowerShell;启动 CDP、断言页面渲染、截图、写 `target/ui-test/ui-smoke.json`)。DSH 沙箱禁止命名管道,WebView2/Chromium 在沙箱内无法启动(窗口白屏、`msedgewebview2.exe` 立即退出),所以这一项只能由用户手动跑。**2026-11-04 已在本机跑通:8/8 checks,截图确认页面正常渲染**(`target/ui-test/ui-smoke.png`,不入库)。
|
||||
- 规则调整(`agent/AGENTS.md`):仓库内新增文件/拆模块不需要事先询问;bug 修复、重构、测试、文档可直接做(每项独立提交);只有仓库外修改、发布、新第三方库(>200 KB vendored 资源)和不变量变化需要先问。
|
||||
- 编辑区样式化(2026-11-06 决定,未开工):**改用内嵌 CodeMirror 5**(MIT、离线 vendored,core + markdown/xml mode + search/fold/lineNumbers 约 +270–320 KB,vendor 时附 LICENSE)。
|
||||
- 理由:行号、**编辑区折叠**、替换已确认近期要做;透明叠加层(方案 A)只能做同字号着色,覆盖不了这三项。自研 contenteditable(方案 B)不做。
|
||||
- 集成前先在 page.js 立**编辑器适配层**(`getValue/setValue/focus/getScrollRatio/setScrollRatio/onChange/setEditable`),textarea 与 CM5 共用同一套 autosave/标签状态/注入逻辑。
|
||||
- 集成要点:编辑模式改为 CM 内部滚动(编辑时隐藏页面滚动条),按标签分别记录编辑/阅读滚动比例;标记保持显示(markdown mode 的 `cm-formatting` 标记 + `cm-strong` 内容加粗);autosave 仍 700ms;替换用 search 插件,阅读模式的既有 find 不动。
|
||||
- 编辑区 CodeMirror 5(2026-11-06 完成,未发布;`8b4d1fa` → `e911876`):
|
||||
- `assets/codemirror/` vendored 5.65.16:core + xml/meta/markdown + searchcursor/search/dialog + foldcode/foldgutter,约 218 KB,附 LICENSE。启动 HTML 不含 CM;首次进编辑通过 `need-editor` IPC 注入,注入失败保留 textarea。
|
||||
- page.js 先抽 `createTextareaEditor`/`createCodeMirrorEditor` 适配层;编辑模式有行号、markdown 着色(标题/加粗/斜体/链接/引用,标记不隐藏)、标题+围栏折叠、CM 内部滚动;页面滚动改到 `#app` 容器,阅读/编辑滚动条都在标签栏下沿。
|
||||
- 折叠:围栏状态按文档缓存、change 行处增量失效;只有开围栏有箭头,折叠包含收尾围栏;代码块里的 `#` 不再当标题。
|
||||
- 查找替换:页面自己的两行 findbar(Find + ↑↓× / Replace + Replace All),Esc 只关查找条;Ctrl+E 退出编辑;阅读模式 find 保持原样。
|
||||
- 滚动:JS `cmTabLines` 按标签记顶部行号,Rust `scroll_ratio` 兜底;`__setContent` 增加第 8 参数 tab id,切标签先加载目标内容、在绘制前滚到行首。
|
||||
- BOM:编辑器值去掉开头 U+FEFF,保存时原样加回;首行标题/围栏识别正常。
|
||||
- 大文档(>2 MB 或 >2 万行)回退 textarea:无行号/折叠/编辑查找。
|
||||
- 已知限制:编辑查找为字面匹配、大小写不敏感,不支持 CM 对话框的 `/re/` 正则;阅读→编辑滚动仍按比例近似;打印只有 CSS 层验证。
|
||||
|
||||
## 12. 测试与验证(2026-11-04 起)
|
||||
|
||||
- 代码级:`cargo test`(当前 60)、`cargo clippy --all-targets`、`cargo fmt -- --check`、`agent\scripts\build.ps1`。
|
||||
- 代码级:`cargo test`(当前 63)、`cargo clippy --all-targets`、`cargo fmt -- --check`、`agent\scripts\build.ps1`。
|
||||
- UI 级:**只能由用户**在桌面 PowerShell 运行 `agent\tests\ui-smoke.cmd`;Agent 读 `target\ui-test\ui-smoke.json` + `ui-smoke.png`。原因与流程见 `HANDOFF.md` §4.1(DSH 沙箱禁止命名管道,WebView2 无法启动)。
|
||||
- 边界:Rust→JS 调用没有编译器检查;改参数必须同步页面签名,并保留 `set_content_script_matches_the_page_signature` 这类测试。
|
||||
- 已验证(2026-11-04):ui-smoke 8/8 checks,截图确认页面正常渲染。
|
||||
- 已验证(2026-11-04、2026-11-06 多次):ui-smoke 8/8 checks,截图确认页面正常渲染。CM5 改版后由用户手动验证编辑/保存/折叠/替换/滚动,ui-smoke 仍 8/8。
|
||||
|
||||
Reference in New Issue
Block a user