fix(sidebar): activate the row whose counts were clicked before opening its diff (#706) (#729)

* fix(sidebar): activate the row whose counts were clicked before opening its diff (#706)

Each sidebar row's `+N −M` opens that row's diff. The counts sit inside
the row and swallow the press so the row does not double-act, but the
row's `on_click` is the only thing that activates a tab, so the click
never switched tabs — and `open_diff_overlay` writes to `self.active`.
Click the counts of an inactive tab B while A is showing and B's
repository, branch and diff landed in A's document area, with A's
`overlay_top` flipped and its own overlay state overwritten by B's
path. Later reads keyed on the active tab carried that state on as A's.

The handler now activates its own row first, so the tab on screen, the
tab the overlay is stored on and the repository shown are one tab. On
the row already active it still toggles, so a second click on the same
counts closes what the first opened; on any other row it opens rather
than toggles, since switching to a tab to see its diff must not close
the diff that tab already had up when it happened to be the same one.
That decision is a small pure function with a test, beside
`diff_click_cwd`, which is the same shape.

Reported with the trace and the fix by @IhpEcVns in #706.

* fix(sidebar): drop the branch whose arms were the same call

counts_click_toggles gated toggle_diff_overlay against open_diff_overlay,
but the first forwards to the second with exactly those arguments — the
toggle lives inside open_diff_overlay, keyed on host/cwd/source/focus and
was_front. Both arms did the same thing, so the helper, its doc and its
test described behaviour the code did not have.

The fix for #706 is the activate() the handler was missing; that stays.
Clicking an inactive row's counts still toggles against that tab once it
is active, which is what shipped before and what ships now.

---------

Co-authored-by: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com>
This commit is contained in:
webdev
2026-08-26 21:35:55 +08:00
committed by GitHub
co-authored by l0ng-ai
parent adb3feb52a
commit d4b8e331b9
+7
View File
@@ -434,6 +434,13 @@ impl Tty7App {
MouseButton::Left,
cx.listener(move |this, _: &MouseDownEvent, window, cx| {
cx.stop_propagation();
// Swallowing the press also swallows the
// row's click, the only thing that
// activates a tab — so this row has to
// activate itself, or the overlay lands
// in whichever tab was already on
// screen, carrying this row's repo (#706).
this.activate(i, window, cx);
this.toggle_diff_overlay(host, cwd.clone(), window, cx);
}),
)