Repository navigation
[6215] 修复目录树开启时 AI 操作栏位置错乱与无法弹出 - #4720
Closed
PinkMagicFly wants to merge 2 commits into
Closed
PinkMagicFly wants to merge 2 commits into
PinkMagicFly wants to merge 2 commits into
Conversation
- selectionRectPixels 改用 surface()->mapTo(parent) 实时映射,删除死 else 分支 - 删除与 mapTo 语义重复的 blank_top_offset() - showPopup/cachePosition 全链移除无人读取的 canvas_x/canvas_y 参数 - showPopup/updatePosition/getCachedPosition 全链移除无人读取的 ren 参数 - 删除 QTMTextPopup 与基类逐字节相同的 updatePosition/scrollBy 覆写 - 移除三个弹窗实现中不再使用的 qt_renderer.hpp 头文件 Co-Authored-By: Claude Code <[email protected]>
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)位置严重右偏或完全无法弹出的问题。问题原因
QTMBasePopup,其父控件为canvas()(即QTMScrollView)。QTMBasePopup::selectionRectPixels中,原本将选区逻辑坐标换算为视口像素坐标时,水平方向直接累加了cached_canvas_x。cached_canvas_x来源于SLOT_POSITION,取值是文档绘制表面surface()相对顶级主窗口(window())的全局 X 偏移。当左侧停靠了目录树大纲侧边栏(OutlineSidebar,宽 300px)时,cached_canvas_x包含了这 300px 宽度。parentWidget()(QTMScrollView)为基准调用move(x, y),水平方向再次向右偏移了 300px。selectionInView()视口判定将选区误判为超出视口右边界而强行隐藏;cursorNearSelection()将鼠标相对scrollarea的真实坐标与右偏 300px 的虚高选区计算距离,差值达 300px 远超 80px 容差门限,导致present()判定光标远离选区而直接隐藏。解决方案
在
QTMBasePopup::selectionRectPixels中,改用 Qt 控件树内部的局部物理坐标映射:通过
owner->scrollarea()->surface()->mapTo(parent, QPoint(0, 0))直接获取文档表面surface相对于悬浮框父控件parent(即scrollarea/canvas)的局部物理像素偏移量(surf_offset_x, surf_offset_y)。该映射发生在
scrollarea内部层级之间,天然隔绝了外部左侧目录树 DockWidget、顶部工具栏及系统窗口边框对局部坐标的干扰;无论目录树展开、收起或尺寸变化,选区像素坐标与悬浮框始终处于同一坐标系中。验证
tests/Plugins/Qt/qt_base_popup_test.cpp,覆盖包含左侧 300px 侧边栏(QDockWidget)的场景,验证x1_px不受 300px 污染且视口判定正常:gf fmt --changed-since=main格式化检查。