From 4aad5e97fccfb000a8f99c00280e29aa4f719dd7 Mon Sep 17 00:00:00 2001 From: omartelo Date: Thu, 22 Oct 2026 17:15:17 -0300 Subject: [PATCH] fix(native): open the active session from a pull request's checkout --- CHANGELOG.md | 1 + native/cmd/lich-native/pulls_actions.go | 22 +++++++++++++++++--- native/cmd/lich-native/pulls_session_test.go | 22 ++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 native/cmd/lich-native/pulls_session_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 11ae9de0..eec93efb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Comments for the session written on a pull request's Files tab in Pulls go to a session in the checkout of that pull request's branch, where Send typed them into whichever session was open before Pulls, reviewing another branch. With no session there, Send says to open one and keeps the comments; Open in Session starts it. A line reference sent from that tab goes the same way. +- Go to session on a pull request in Pulls opens the session you are in when it sits in the pull request's checkout, where it always opened the first session there. - On Windows with display scaling above 100%, a drag follows the pointer again: an item dragged in Settings › Footer or a selection dragged in the terminal landed away from the cursor, scaled as if the screen were at 100%. - Review comments sent to a session are kept until the session takes them. A session that refused the batch (one that had stopped, say) showed "Couldn't send the comments" while the comments were already gone; they now stay in the batch to send again. Likewise, submitting a pull request review in Pulls drops only the comments it carried, where a comment written while the review was on its way was lost with them. - On Windows, the window wears lich's icon and opens under lich's taskbar button, where it showed a generic icon and, launched from a lich pinned to the taskbar, opened as a separate button beside the pin. diff --git a/native/cmd/lich-native/pulls_actions.go b/native/cmd/lich-native/pulls_actions.go index 14d1932a..f05747c0 100644 --- a/native/cmd/lich-native/pulls_actions.go +++ b/native/cmd/lich-native/pulls_actions.go @@ -175,9 +175,9 @@ func (u *window) prSession(project lichclient.Project, d lichclient.PRDetail) (s return u.addWorktreeSession(worktreeRequest{project: project, kind: u.model.newSessionKind()}, wt, "") } existing := checkouts[i] - if ids, _, _ := u.model.sessionsAt(project.ID, existing.Path); len(ids) > 0 { - u.openSession(project.ID, ids[0]) - return ids[0], nil + if id, ok := u.model.sessionToOpenAt(project.ID, existing.Path); ok { + u.openSession(project.ID, id) + return id, nil } if existing.Path == project.Path { return u.newSessionAt(project, existing.Path) @@ -314,6 +314,22 @@ func (m *model) sessionsAt(projectID, path string) (ids []string, pinned bool, r return ids, pinned, len(m.status.running(ids)) } +// sessionToOpenAt is the session the window brings up for path: the one on +// screen when it sits there, else the first; false when none does. +func (m *model) sessionToOpenAt(projectID, path string) (string, bool) { + ids, _, _ := m.sessionsAt(projectID, path) + if len(ids) == 0 { + return "", false + } + m.mu.Lock() + active := m.active + m.mu.Unlock() + if slices.Contains(ids, active) { + return active, true + } + return ids[0], true +} + // removeConfirm asks before removing a worktree whose sessions are mid-turn, // which the merge notice likely just woke. type removeConfirm struct { diff --git a/native/cmd/lich-native/pulls_session_test.go b/native/cmd/lich-native/pulls_session_test.go new file mode 100644 index 00000000..4baec25c --- /dev/null +++ b/native/cmd/lich-native/pulls_session_test.go @@ -0,0 +1,22 @@ +package main + +import "testing" + +func TestSessionToOpenAtPrefersTheActiveSession(t *testing.T) { + m, _ := newLayoutsModel(t) + m.active = "notes" + if id, ok := m.sessionToOpenAt("lich", "/dev/lich"); !ok || id != "notes" { + t.Fatalf("opened %q (%v), want the active session notes", id, ok) + } +} + +func TestSessionToOpenAtFallsBackToTheFirstSession(t *testing.T) { + m, _ := newLayoutsModel(t) + m.activeProject, m.active = "plugin", "wb" + if id, ok := m.sessionToOpenAt("lich", "/dev/lich"); !ok || id != "orch" { + t.Fatalf("opened %q (%v), want the first session orch", id, ok) + } + if id, ok := m.sessionToOpenAt("lich", "/dev/elsewhere"); ok { + t.Fatalf("opened %q in a checkout without sessions", id) + } +}