Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[0840] AI Suggestion 功能初步实现
1 相关文档
2 任务相关的代码文件
TeXmacs/progs/generic/generic-kbd.scm— 注册kbd-tab键盘钩子以引入diff-text模块TeXmacs/progs/generic/diff-text.scm— 新增diff-text模块,实现富文本 AST 树级递归修改生成、自愈式双重重载按键拦截及鼠标环境自适应检测逻辑src/Edit/editor.hpp/src/Edit/Interface/edit_interface.hpp— 添加show_diff_popup/hide_diff_popup的编辑器接口声明src/Edit/Interface/edit_mouse.cpp— 实现编辑器接口转调至 Qt 侧简易部件弹窗接口src/Scheme/Glue/glue_editor.lua— 为show_diff_popup/hide_diff_popup注册 Scheme 与 C++ 黏合绑定src/Plugins/Qt/QTMUserPromptPopup.hpp/QTMUserPromptPopup.cpp— 重构基类QTMUserPromptPopup支持子类自定义按钮文本(“接受 Enter”/“拒绝 Backspace”),并实现派生子类QTMDiffTextPopupsrc/Plugins/Qt/qt_simple_widget.hpp/qt_simple_widget.cpp— 管理diffTextPopup弹窗实例的生命周期、显示隐藏与滚动src/Plugins/Qt/QTMWidget.cpp— 增加滚动事件监听,确保页面滚动时差异对比弹窗同步跟随滚动3 如何测试
3.1 确定性测试(单元测试)
3.2 非确定性测试(交互验证)
xmake f --is_community=false && xmake b stem)构建 MoganSTEMTeXmacs\tests\tmu\0840.tmutab触发一个 AI Suggestion 的 demo(随机删除一些the,插入一些a,大写一些单词)tab也会触发 AI Suggestion,逻辑相同version-both节点间跳转,弹窗会自动贴合光标位置version-both节点,弹窗会自动贴合光标位置version-both节点后,可以通过快捷键Enter/Backspace来同意或拒绝当前的差异对比,会立刻生效xmake f --is_community=true && xmake b stem)构建 MoganSTEM,上述功能不被触发4 What
在自动补全框架下进一步设计并实现了基于富文本 AST 对照的差异对比预览(Diff Text)交互系统:
5 How
在
diff-text.scm中,设计demo-suggest函数递归扫描选区树,保持原有树节点拓扑外壳,仅在叶子文本节点上应用随机的删除、增加与大写变换逻辑。在同意(
accept-diff)或拒绝(reject-diff)时,通过tree-remove!在位移除当前的version-both节点,并在光标前执行(insert ...)原地写入纯文本内容。通过在
keyboard-press增加双重函数重载分发,区分高优先级决策按键拦截(回车/退格)与低优先级常驻事件监听。当光标被流转至下一处或通过鼠标、方向键位移至version-both节点内部时,延迟调用diff-check-popup。在其中先隐后显,确保弹窗位置始终自适应贴合最新光标。重构基类
QTMUserPromptPopup构造函数接收acceptText与rejectText参数,并在子类QTMGhostTextPopup与QTMDiffTextPopup中调用基构造函数定义特定的提示文案。