Files
mnote/bugs/05-editor-mainline/done/2026-05-27-filetree-create-page-bundle-auto-expand.md
T

2.1 KiB
Raw Blame History

FileTree 连续新建页面会展开上一个页面包目录

状态:done Owner05-editor-mainline / 04-tree-domain 发现日期:2026-05-27 来源:用户反馈 / Sidex Explorer 行为对照

现象

在 local folder 的“我的空间”中连续点击新建页面时,FileTree 会先短暂显示内部 .md 行,然后折叠;再次新建页面后,上一个页面包目录会被自动展开,当前页面包目录保持折叠,视觉上像是展开状态串到了旧页面。

根因

本地页面是 页面名/页面名.md 的同名目录包。新建完成后,前端 selectSidebarFileTreeDocument(...) 找不到折叠目录内部的 .md 行,会调用 revealFileTreeResource(...) 展开目录包并持久化展开状态。后端 load_local_folder_file_tree_snapshot_with_reveal(...) 也会把同名页面包目录当作普通祖先展开,导致下一次刷新时旧页面包恢复展开。

Sidex / VSCode Explorer 的对齐原则是:刷新 collapsed 节点只标记 stalereveal 只展开必要祖先,不应把当前资源自身的内部实现目录当作用户展开状态持久化。

修复

  • local-md: 路径解码改为完整 ~XX -> %XX -> decodeURIComponent,避免中文路径无法匹配可见目录包行。
  • 前端选择 local markdown 时,若目标是同名页面包 目录/目录.md 且目录包行已可见,则直接选中/激活目录包行,不展开内部 .md
  • 后端 FileTree reveal 对同名页面包只展开到页面包父级,不扫描并展开包内部 .md
  • task494-filetree-lazy-loading-dedup-smoke.js 增加连续新建页面回归:上一个页面包不自动展开,当前页面包不展开内部 md,当前页面包行保持 active。

验证

  • node scripts/task494-filetree-lazy-loading-dedup-smoke.js 先失败于上一个页面包 expanded=true,修复后通过。
  • cargo test --manifest-path rust/Cargo.toml -p mnote-web filetree -- --nocapture --test-threads=146 passed。
  • cargo test --manifest-path rust/Cargo.toml -p mnote-web local_file_tree -- --nocapture --test-threads=14 passed。