fix(desktop): 修复代码块复制按钮 tooltip 定位偏左的问题#4069
Open
whale-fall-ouo wants to merge 1 commit into
Open
Conversation
SivanCola
requested changes
Jun 12, 2026
SivanCola
left a comment
Collaborator
There was a problem hiding this comment.
当前需要先处理 base drift,不能直接合入。
最新 main-v2 已在 8ec1130 / #4059 改掉了这条代码路径:CopyButton 不再用 Tooltip 包裹,而是在按钮内部用 .copybtn__label-inline 显示提示,并且代码块按钮已移动到 HljsCode 的
内。这个 PR 仍然基于旧实现给 Tooltip 增加 triggerRef,所以和最新 main-v2 合并时会在 desktop/frontend/src/components/CopyButton.tsx 产生内容冲突。我本地验证:git merge-tree --write-tree origin/main-v2 refs/remotes/origin/pr/4069 退出 1,并报告 CopyButton.tsx content conflict。
建议先 rebase 到最新 main-v2。rebase 后如果 #3867 在当前 inline-label 实现下已经不存在,这个 PR 可以关闭为 superseded;如果问题仍能复现,需要基于当前 HljsCode/CopyButton 结构重新修,而不是恢复旧的 Tooltip 包裹路径。
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.
问题描述
代码块的复制按钮 hover 时,tooltip 显示在屏幕最左侧,而非按钮旁边。
根因分析
CopyButton 使用 Tooltip 包裹 button,Tooltip 默认用 span 包裹子元素。但复制按钮使用了
position: absolute(脱离文档流),导致 wrapper span 的宽度为 0。Tooltip.updatePosition()对这个零宽度 span 调用getBoundingClientRect(),得到的rect.left是 code-block 的最左端,tooltip 就显示在了错误的位置。修复方案
在 Tooltip 组件中新增可选
triggerRef外部 ref 支持:triggerRefprop,updatePosition优先使用外部 ref 的元素来计算位置triggerRefwrapper span 仍保留用于事件绑定(hover/focus),位置计算改用 button 自身的实际位置。改动不影响其他 Tooltip 使用场景(
triggerRef是可选的)。涉及文件
Tooltip.tsxtriggerRefprop,updatePosition优先使用它CopyButton.tsxtriggerRefFixes #3867