Skip to content

feat(macos): 对齐 IDEA 的分支弹窗交互模式 - #392

Merged
1lck merged 6 commits into
previewfrom
worktree-branch-popup-idea-alignment
Sep 2, 2026
Merged

feat(macos): 对齐 IDEA 的分支弹窗交互模式#392
1lck merged 6 commits into
previewfrom
worktree-branch-popup-idea-alignment

Conversation

@xiaoyumuxi

@xiaoyumuxi xiaoyumuxi commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

背景

当前分支弹窗存在两个问题:

  • 单击分支行会直接 checkout。 扫描分支列表时一次误触就会切换工作树,而 checkout 本应只能通过右键菜单触达。
  • 被截断的行没有办法看到完整名称。 弹窗宽度固定,较长的 branch 和 upstream 名称(如 origin/codex/res…)被截断后无法在悬停时查看全名。

改动

macos/Sources/Lithe/Views/Git/BranchSwitcherPopover.swift

  • branchRow 从直接 checkout 的 Button 改成 BranchActionMenuRow,使用 SwiftUI.Menu + .menuStyle(.borderlessButton),左键打开 native NSMenu。
  • 操作菜单项顺序对齐 IDEA:New Branch from '…'、Show Diff with Working Tree、Compare with Current Branch,然后是 Checkout(仅非当前分支),再是 Update / Push…,最后是 Delete(本地且非当前分支)。
  • dismissAndRun 在执行操作前先关闭弹窗,防止操作触发的 sheet 出现在即将消失的 popover 后面。
  • 通过 .help(branchRowTooltip(_:)) 在悬停时展示完整的 branch → upstream 名称对,解决截断问题。
  • native NSMenu 自带 IDEA 的 hover 安全路径:一旦某行菜单打开,鼠标移到相邻行会立即展开该行菜单,无需再次点击;菜单也会自动避开屏幕边缘。

macos/Tests/LitheTests/BranchSwitcherPopoverBehaviorTests.swift(新增)

三个源码契约测试,锁定关键行为:分支行必须通过 BranchActionMenuRow 呈现、model.checkoutReference 只能有一个调用点且必须挂在 Checkout 菜单项下的 dismissAndRun 里、hover tooltip 必须存在。

验证

  • swift build --target Lithe — 通过
  • ./scripts/verify-service-boundaries.sh — 通过
  • swift test --filter BranchSwitcherPopoverBehaviorTests — 3/3 通过

改动仅限 Views 层,未涉及 model、service 或 contract。合并前建议手动确认:hover 到相邻行时菜单是否无延迟切换、tooltip 是否在长名称行上正常显示。

The branch popup checked out a reference on a plain click, so scanning the
list could switch the working tree by accident; checkout was otherwise only
reachable through the right-click menu.

Branch rows now present their actions through a native pop-up menu, with
Checkout as one explicit entry. The native menu also supplies IDEA's
hover-safety path: once a row's menu is open, moving to another row opens
that menu without a click. Rows whose branch or upstream name the fixed
popup width truncates expose the full pair as a hover tooltip.
@xiaoyumuxi
xiaoyumuxi requested a review from 1lck as a code owner September 1, 2026 13:54
@xiaoyumuxi

Copy link
Copy Markdown
Collaborator Author
image

@xiaoyumuxi xiaoyumuxi changed the title feat(macos): align branch popup rows with IDEA's action menu feat(macos): 对齐 IDEA 的分支弹窗交互模式 Sep 1, 2026
1lck and others added 3 commits September 1, 2026 22:19
The testing helper detaches into its own process group, so the previous
group-scoped walk only sampled the shell wrapper waiting on its child.
Walk the ppid tree instead and capture a listing plus a thread-stack
sample of every descendant before terminating the run.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@1lck

1lck commented Sep 2, 2026

Copy link
Copy Markdown
Owner

@xiaoyumuxi 更正一下上一条 Review:我把 PR #392 从 base 到 head 的整体 diff 与本次功能提交混在了一起,错误地将 Swift test watchdog 的问题作为本 PR 的阻塞问题。

经重新核对提交归属:分支弹窗功能提交是 b7083369c5a7d4a8;watchdog 相关的 4a9e569d1563dec4 是由 lick 之前带入的 CI 提交,并不是你这次分支弹窗功能的实现。因此,这条 watchdog 行级评论已撤回,不应作为对你本次功能代码的缺陷归因。

保留的范围判断是:这些 CI 提交确实出现在当前 PR 的整体 diff 中,最好通过正确的 base/rebase 或单独 PR 管理,避免功能改动与基础设施改动耦合;但这属于提交组织建议,不应据此阻塞分支弹窗功能本身。

按你的实际功能提交重新判断,目前未发现需要阻塞合并的分支弹窗代码问题。剩余验证缺口主要是 macOS 原生 Menu 的相邻行 hover 切换、长名称 tooltip,以及完整 macOS 构建/行为测试的实际运行验证。分支行改为显式 action menu、删除操作接入确认流程,以及新增的行为契约测试仍然值得保留。

@xiaoyumuxi

Copy link
Copy Markdown
Collaborator Author

@xiaoyumuxi 这次 Review 主要核对了分支弹窗改动及 PR 实际包含的测试基础设施变更。分支行从直接 checkout 改为显式 action menu、删除操作接入工作台确认流程、长分支名增加 tooltip,这几个方向与背景需求一致,代码职责也仍在 macOS Views 层;新增的行为契约测试也覆盖了核心点击路径,值得保留。

目前存在 1 个需要阻塞合并的问题:PR 同时带入了与分支弹窗无关的 Swift 测试 watchdog 改动,而 stall watchdog 在终止测试进程前同步执行最多 6 次 sample,每次最多 15 秒,真实 macOS stall 时可能把终止推迟约 90 秒。具体复现步骤和修改建议已写在对应行级评论中。

另外,PR 描述称改动仅限 Views、model、service 和 contract 未涉及,但实际 diff 还包含 5 个 write-stable-tests 文件的大量变更。建议将这部分从本 PR 拆出或先 rebase 到包含该基础设施改动的基线,避免分支弹窗功能和测试运行器变更混在一起。当前 GitHub 没有报告该分支的 CI checks,且 PR 状态为 conflicting;合并前还需要补一次完整 macOS 构建、行为测试和真实 stall 清理验证。

那一部分是你们之前合入的,但是我迁出分支的时候还没有这个改动,为了CI过掉,我直接去将你们合入的改动拉上来了因此才会出现这种耦合的样子

@xiaoyumuxi
xiaoyumuxi changed the base branch from main to preview September 2, 2026 02:21
@1lck

1lck commented Sep 2, 2026

Copy link
Copy Markdown
Owner

这个pr没啥问题了 解决一下冲突就可以合了

1lck
1lck previously approved these changes Sep 2, 2026
@1lck
1lck merged commit 783a96f into preview Sep 2, 2026
11 checks passed
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.

2 participants