Skip to content

[6013] 实现 STEM 左侧目录树功能(PDF 书签与 TMU/STEM 章节大纲) - #4698

Merged
da-liii merged 9 commits into
mainfrom
da/6013/outline_sidebar
Oct 10, 2026
Merged

da-liii merged 9 commits into
mainfrom
da/6013/outline_sidebar

Conversation

@da-liii

@da-liii da-liii commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

本 PR 规划并实现了 Mogan STEM 的左侧目录树功能,同时支持 PDF 阅读模式与 TMU / STEM 文档编辑模式下的多级章节大纲导航。

主要变更

  1. Scheme 逻辑层(TeXmacs/progs/text/text-outline.scm)

    • 修复模块依赖,导入 (text text-drd) 与 (text text-structure),解决 tm/section-get-title-string 报 unbound variable 的 bug;
    • 建立覆盖 part 到 subsubsection 的数值化层级映射 section-level;
    • 提取纯净标题文本 outline-clean-title,妥善处理公式与宏;
    • 纯函数式单调层级构树算法 build-outline-tree,生成多层嵌套大纲结构 ((title path-str (child ...)) ...);
    • 提供 (outline-go-to path-str) 导航过程,配合 (make-cursor-visible u) 驱动主编辑区视口居中滚动与光标就位。
  2. QML 现代化控件与 C++ 桥接(OutlineSidebar.qml & OutlineBridge & qt_pdf_outline_widget)

    • 使用 QML 重构目录侧边栏,依托 Theme 单例原生适配深浅双色主题;
    • OutlineBridge 为树节点赋予全局唯一 node.id,消除相同页码节点折叠冲突;
    • 右侧对齐页码、树形导引线(纯单层章节自动隐藏分支符)、同源矢量中心旋转三角指示符;
    • 顶栏搜索框与三点「···」展开/折叠更多菜单;
    • 支持侧边栏尺寸与宽度记忆。
  3. 主窗口多 Tab 切换联动与双向事件分发(qt_tm_widget.cpp)

    • 连接 outlineActivated 信号:PDF 模式驱动翻页,编辑模式驱动章节定位居中滚屏与焦点同步;
    • 在 SLOT_FILE 挂载生命周期同步,自适应 PDF 书签、STEM 章节大纲与空白状态。
  4. 主题适配与菜单集成

    • 在 liii.css 与 liii-night.css 中注入侧边栏样式;
    • 在【查看】(View)菜单中新增【目录】开关;
    • 默认开启目录侧边栏偏好。
  5. 全量测试保障

    • Scheme 纯逻辑单元测试:TeXmacs/tests/6013.scm(26/26 checks passed);
    • Qt C++ 单元测试:tests/Plugins/Qt/qt_outline_widget_test.cpp(8/8 passed);
    • PDF 阅读器单元测试:tests/Plugins/Qt/qt_pdf_reader_widget_test.cpp(49/49 passed);
    • 集成测试:TeXmacs/tests/1322.scm(6/6 passed);
    • 端到端自动化测试:dev-agent 仓库 tests/mogan/python/6013.py。

- Scheme 层重构 text-outline.scm:修复模块依赖,规范章节层级判定(part 到 subsubsection),提取纯净标题,实现递归嵌套构树算法与 outline-go-to 光标滚动定位
- C++ 侧重构 OutlineWidget:递归解析嵌套大纲构建具有父子关系的 QTreeWidget,新增操作顶栏(全部展开/折叠/关闭按钮),打通编辑器模式点击定位与键盘焦点恢复
- 多 Tab 联动:在 SLOT_FILE 挂载大纲刷新调度,在 PDF 书签、STEM 大纲及启动页之间自适应切换
- 界面与主题:在 liii.css 与 liii-night.css 中完善目录树样式规范,在【查看】菜单新增【目录】开关项
- 默认启用:解除旧版本的探索性屏蔽,默认开启大纲目录树
- 自动化测试:新增 Scheme 单元测试(TeXmacs/tests/6013.scm)、Qt C++ 单元测试(tests/Plugins/Qt/qt_outline_widget_test.cpp)及 Python 端到端自动化测试脚本(TeXmacs/tests/python/6013.py)
- 使用 QML (OutlineSidebar.qml) 重构目录侧边栏界面,全面适配深色与浅色主题
- 将全部展开/折叠功能移至搜索框右侧的三点「···」弹出菜单
- 优化树形导引线与层级缩进,单层章节时去除冗余分支符,节点支持右侧对齐页码
- 修复基于唯一 node.id 的单项折叠展开逻辑,支持三角指示符点击与整行双击展开/收起
- 完善侧边栏尺寸与宽度边界,支持用户拖拽记忆与持久化
- 完善 Python 端到端鼠标交互测试脚本,断言真实点击导航与跳转
- 在 outline-go-to 与 C++ 激活槽中补齐 make-cursor-visible 调用,确保点击章节时光标与文档视口自动居中滚动到位
- 使用旋转几何保持折叠与展开状态下 chevron 箭头尺寸完全对称一致(11px 粗体)
@da-liii
da-liii force-pushed the da/6013/outline_sidebar branch from 766d49d to 7f44018 Compare October 10, 2026 05:53
@da-liii
da-liii marked this pull request as ready for review October 10, 2026 05:53
da-liii and others added 5 commits October 10, 2026 14:16
- 删除 QTreeWidget 时代遗留的失效 CSS(两份主题各 ~104 行)与无调用方的 document-outline-widget
- OutlineBridge 移除只写不读的 currentTarget 与单参 itemClicked,合并 convert 样板为 makeNode
- qt_tm_widget 提取 restore_outline_dock_width 替代 3 处复制块,并移除 SLOT_FILE 中重复的大纲加载
- 侧边栏宽度偏好改为 300ms 防抖写盘,QML setSource 延迟到首次显示
- QML 搜索改为单遍自底向上匹配 + 200ms 防抖,弹出菜单合并为 Repeater
- 修复 outline sidebar 偏好默认值 C++/scheme 两层不一致导致菜单勾选状态错位
- 测试补齐 cleanup/QTEST_MAIN 规范,qml_load_test 新增 OutlineSidebar 加载用例

Co-Authored-By: Claude <[email protected]>
@da-liii
da-liii requested a review from MoonL79 October 10, 2026 07:39

@MoonL79 MoonL79 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@da-liii
da-liii merged commit 89247a7 into main Oct 10, 2026
5 of 6 checks passed
@da-liii
da-liii deleted the da/6013/outline_sidebar branch October 10, 2026 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants