Repository navigation
[6232] 修复目录树开启时 AI 操作栏悬浮错乱 - #4764
Merged
Merged
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.
概述
修复开启左侧目录树(OutlineSidebar)或侧边栏时,选中文本后 AI 操作栏(
QTMAiActionsBar)位置严重右偏或完全无法弹出的问题。任务文档见 LiiiLabs/dev-agent 的 devel/6232.stem。问题原因
QTMBasePopup::selectionRectPixels把选区逻辑坐标换算为视口像素坐标时,水平方向累加了调用链传入的cached_canvas_x。cached_canvas_x来源于get_canvas_x()(SLOT_POSITION),取值是文档绘制表面surface()相对顶级主窗口的全局 X 偏移。当左侧停靠了目录树侧边栏(宽约 300px)时,该偏移包含了这 300px 宽度。parentWidget()(QTMScrollView)局部坐标为基准调用move(x, y),全局偏移混入局部坐标导致右偏约 300px;虚高坐标又使selectionInView()把选区误判为超出视口右边界而强行隐藏,并使cursorNearSelection()的鼠标距离超出容差门限,present()判定光标远离选区而直接隐藏。解决方案
在
QTMBasePopup::selectionRectPixels中,改用 Qt 控件树内部的局部坐标映射:通过owner的scrollarea的surface()调用mapTo(parentWidget(), QPoint(0, 0))实时取得文档表面相对悬浮框父控件的局部偏移。该映射发生在 scrollarea 内部层级之间,天然隔绝目录树 DockWidget、顶部工具栏及系统窗口边框对局部坐标的干扰;surface 在视口中以水平垂直居中摆放,映射结果自动涵盖视口大于表面时的居中留白,故同时删除blank_top_offset()补偿以避免双重计算。共用该基类的 AI 操作栏、图片工具栏、文本工具栏一并修复。与 #4720 的差异:本 PR 仅保留坐标修复本体,
show_ai_actions_bar等调用链签名与cached_canvas_x字段保持不变,保持最小改动面。验证
tests/Plugins/Qt/qt_base_popup_test.cpp,在普通 QWidget 宿主中的 QTMScrollView 上,以 300×PIXEL 模拟带侧边栏时get_canvas_x的全局偏移传入cachePosition,断言选区像素宽度精确保持、x 坐标等于 surface 相对父控件的实际偏移、selectionInView判定选区在视口内:gf fmt --check通过。