Fix: 候选词面板首次聚焦时漂移到屏幕左上角#1126
Open
Songggggr wants to merge 1 commit intorime:masterfrom
Open
Conversation
…tion for proper layout handling
b982913 to
69bc124
Compare
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 处理了,效果不错 #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] 不影响其他模块。