[0986] 选中文字后下一行出现 AI 操作栏(AI翻译/AI润色/AI对话,一键翻译第一步) - #4555
Merged
Conversation
PinkMagicFly
force-pushed
the
pigmagicfly/0986/ai-translate
branch
from
September 14, 2026 03:43
e5d8b9e to
9ebb181
Compare
This reverts commit c6a554e.
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.
一键 AI 翻译 · 第一步:选区下方 AI 操作栏
任务文档:
devel/0986.md。整个功能分两个 PR,本 PR 为第一步(仅悬浮 UI),点击按钮后的提示词拼接与侧边栏自动发送在第二步实现。
What
选中文字后,在选中文字的下一行出现一行 AI 操作栏:
get_selection_last_rect:屏幕最下方、同行最右的选区矩形)左缘对齐、位于其下方;下方放不下时退到选区上方,始终
裁剪在视口内
("ai translate" "AI翻译")、("ai polish" "AI润色")、("ai chat" "AI对话"))(或按 Esc)后本次选区内不再弹出,选区变化后自动复位
tmfs://内嵌页面、数学/代码/verbatim 上下文不弹出How
复用现有悬浮 popup 体系(
QTMBasePopup/QTMTextPopup家族):QTMAiTranslatePopup(继承QTMBasePopup):一行三个QPushButton,getCachedPosition定位到选区下一行;autoSize按选区最小文字渲染高度缩放字号与内边距
QTMBasePopup新增blank_top_offset()助手,消除「视口高于画布表面时顶部居中留白补偿」的三处复制
get_selection_geometry单次search_selection遍历产出(最末矩形 + 最小高度),避免每次更新遍历两遍排版树;顺带修复了最小高度
计算的符号错误(选区矩形不变式 y1 < y2,原
y1 - y2恒为负导致恒退回默认字号)
USE_TEXT_TOOLBAR编译宏(该宏默认关闭,且是另一套按钮组),AI 操作栏独立默认开启
apply_changes)、键盘(含 Escdismiss)、鼠标移动、滚动(
QTMWidget::scrollContentsBy)、点击选区外隐藏;选区移出视口由 popup 侧
selectionInView判定隐藏单元测试
editor_rep基类新增带默认实现的虚函数get_selection_min_height/selection_last_rect_array(仿is_pre_editing模式),经glue_editor.lua暴露为(selection-min-height)/(selection-last-rect)TeXmacs/tests/0986.scm钉选区几何语义,但 headless 下断言依赖异步排版、无法稳定同步执行(还触发过游标路径崩溃),已移除;几何
语义(末行定位、最小字号联动)由手动 GUI 验证覆盖
验证
xmake b stem构建通过(含 glue 重新生成)gf fmt --changed-since=main已跑,格式化改动仅落在本任务文件xmake b qml_load_test && xmake r qml_load_test:24 用例全过,含test_ai_actions_bar_loads(QML 操作栏加载)与test_ai_actions_bar_hover(无按键 move 直接点亮/熄灭按钮胶囊——纯悬浮链路回归用例)
更新:修复按钮纯悬浮不点亮
WA_NativeWindow:macOS 上原生子窗口收不到无按键mouseMoved,按钮纯悬浮不点亮、按住拖动/点击才反应。已去掉该属性(圆角
透明经顶层 backing store 合成即可),并补交此前未入库的
AiActionsBar.qml与图标资源(此前远端分支缺这两个资源,无法正常弹出)showPopup显示后按当前光标位置向离屏 scene 发一次 HoverMove(
syncHover),纠正上次会话残留的 hover 态(弹窗可能在静止光标正下方弹出/重定位,不会有鼠标事件到来)
(
qt_use_software_scene_graph/qt_inject_theme_context/qt_is_dark_theme,QTMQmlDialog 与 qt_utilities 原四处内联判定同步替换);autoSize按字号缓存去重,选区存续期间的高频 showPopup 不再重复触发 QML重排与定尺寸;测试侧 AiActionsBar 两用例共用 make_ai_actions_bar 脚手架
🤖 Generated with Claude Code