Skip to content

Fix: 候选词面板首次聚焦时漂移到屏幕左上角#1126

Open
Songggggr wants to merge 1 commit intorime:masterfrom
Songggggr:feat/position
Open

Fix: 候选词面板首次聚焦时漂移到屏幕左上角#1126
Songggggr wants to merge 1 commit intorime:masterfrom
Songggggr:feat/position

Conversation

@Songggggr
Copy link
Copy Markdown

@Songggggr Songggggr commented Apr 25, 2026

经常会遇到这个问题,有点难受,用 AI 处理了,效果不错 #870

问题描述
在中文输入模式下,首次聚焦某个可输入区域(如 Chrome 搜索框)时,候选词面板会漂移到屏幕左上角。第二次及之后输入则正常。

根因分析
rimeUpdate() 中 show() 调用 client.setMarkedText() 后,紧接着 showPanel() 调用 client.attributes(forCharacterIndex:lineHeightRectangle:) 查询光标位置。某些客户端(如 Chrome 多进程架构)在收到 setMarkedText 后尚未完成布局,此时 attributes 返回的 lineHeightRectangle 接近 (0,0),导致候选框定位到屏幕左上角。

修复内容
延迟 showPanel 到下一个 run loop:给客户端一个 run loop 迭代的时间处理 setMarkedText 并完成布局,使 attributes 能返回正确的光标位置

增加位置有效性校验:即使延迟后仍可能拿到无效位置,增加 height > 0 且 origin 偏离屏幕原点 的双重校验;无效时保留前一次有效位置,若无前位置则用鼠标坐标兜底;使用 abs() 判断支持多显示器负坐标场景

影响范围
仅修改 [SquirrelInputController.swift] 不影响其他模块。

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.

1 participant