From 9e28aeb80c8bc5e1a2bf9a91ae695ab4f5eab071 Mon Sep 17 00:00:00 2001 From: Amit Ghadge Date: Sun, 15 Nov 2026 16:30:18 -0800 Subject: [PATCH] Commit graph: close a commit's panel, and step back with Escape MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clicking a commit opened its panel and nothing closed it, so the graph never came back to its whole width. An × on the panel and a second click close it; Escape, while the graph has the keyboard, closes the newest thing opened: CI, Autopilot, a comparison, the commit, a branch's focus. Co-Authored-By: Claude Opus 5.5 --- macos/Sources/ConchApp/CommitsView.swift | 61 ++++++++++++++++++- macos/Sources/ConchKit/CommitGraph.swift | 23 +++++++ .../ConchKitTests/BranchGraphTests.swift | 19 ++++++ 3 files changed, 101 insertions(+), 2 deletions(-) diff --git a/macos/Sources/ConchApp/CommitsView.swift b/macos/Sources/ConchApp/CommitsView.swift index 1e67b610..07f023e1 100644 --- a/macos/Sources/ConchApp/CommitsView.swift +++ b/macos/Sources/ConchApp/CommitsView.swift @@ -384,8 +384,13 @@ final class CommitsModel: ObservableObject { } } - /// Picks a commit, or with shift a second one to compare with it. + /// Picks a commit, or with shift a second one to compare with it; the + /// picked one clicked again closes its panel. func pick(_ hash: String, shift: Bool) { + if pickCloses(hash, selected: selected, shift: shift, comparing: compareWith != nil) { + closeCommit() + return + } if shift, let s = selected, s != hash { compareWith = hash } else { @@ -395,6 +400,29 @@ final class CommitsModel: ObservableObject { loadDetail() } + /// Closes the commit's panel: the graph is whole again. + func closeCommit() { + selected = nil + compareWith = nil + detail = nil + detailError = "" + peekFile = nil + peek = [] + } + + /// One step back (Escape): the newest thing opened closes first. + func back() { + switch graphBack(showCI: showCI, showAutopilot: showAutopilot, comparing: compareWith != nil, + selected: selected != nil, focused: focusOn != nil) { + case .closeCI: showCI = false + case .closeAutopilot: showAutopilot = false + case .endCompare: compareWith = nil; loadDetail() + case .closeCommit: closeCommit() + case .clearFocus: focusOn = nil + case .nothing: break + } + } + /// The range being compared, the older commit first, by the graph's order. var range: (from: String, to: String)? { guard let a = selected, let b = compareWith else { return nil } @@ -496,6 +524,9 @@ struct CommitsView: View { .sheet(isPresented: Binding(get: { model.reviewing != nil }, set: { if !$0 { model.reviewing = nil } })) { RebaseReviewSheet(model: model) } + // Only while the graph has the keyboard: Escape belongs to the + // terminals and agents in the other splits. + .onExitCommand { model.back() } } var graph: some View { @@ -804,12 +835,20 @@ struct CommitDetailPanel: View { var body: some View { ScrollView { VStack(alignment: .leading, spacing: 10) { + // Still reading, or it failed: the × has no header to sit in. + if model.detail == nil { + HStack { Spacer(); CloseCommitButton(model: model) } + } if !model.detailError.isEmpty { Text(model.detailError).font(.ui(size: 12)).foregroundStyle(Theme.err) } if let d = model.detail { if let r = model.range { - Text("Compare").font(.ui(size: 11, weight: .semibold)).foregroundStyle(Theme.merged) + HStack { + Text("Compare").font(.ui(size: 11, weight: .semibold)).foregroundStyle(Theme.merged) + Spacer() + CloseCommitButton(model: model) + } Text("\(d.commits ?? 0) commit\((d.commits ?? 0) == 1 ? "" : "s"), \(d.files?.count ?? 0) file\((d.files?.count ?? 0) == 1 ? "" : "s")") .font(.ui(size: 14, weight: .semibold)) Text("\(String(r.from.prefix(7))) → \(String(r.to.prefix(7)))").font(.ui(size: 11.5, design: .monospaced)).foregroundStyle(Theme.muted) @@ -822,6 +861,7 @@ struct CommitDetailPanel: View { NSPasteboard.general.clearContents() NSPasteboard.general.setString(d.hash, forType: .string) }.controlSize(.small) + CloseCommitButton(model: model) } Text(d.subject ?? "").font(.ui(size: 14, weight: .semibold)).fixedSize(horizontal: false, vertical: true) HStack(spacing: 6) { @@ -1274,3 +1314,20 @@ struct ConflictCard: View { .overlay(RoundedRectangle(cornerRadius: 8).stroke(tone.opacity(0.35))) } } + + +/// The commit panel's ×: back to the whole graph (Escape does it too). +struct CloseCommitButton: View { + @ObservedObject var model: CommitsModel + /// Read so the × is drawn again when the theme changes. + @Environment(\.conchTheme) private var look + + var body: some View { + Button { model.closeCommit() } label: { + LucideIcon("x", color: Theme.muted, size: 13).padding(3).contentShape(Rectangle()) + } + .buttonStyle(.plain) + .help("Close — back to the whole graph (Esc)") + .accessibilityLabel("Close the commit") + } +} diff --git a/macos/Sources/ConchKit/CommitGraph.swift b/macos/Sources/ConchKit/CommitGraph.swift index 30a04943..e5f5e976 100644 --- a/macos/Sources/ConchKit/CommitGraph.swift +++ b/macos/Sources/ConchKit/CommitGraph.swift @@ -170,3 +170,26 @@ public func lanePalette(_ t: ConchTheme) -> [RGB] { } return out } + +/// What one step back does in the commit graph — Escape, or the panel's +/// close button — the newest thing opened first, until the graph is whole +/// again with nothing picked. +public enum GraphBack: Equatable, Sendable { + case closeCI, closeAutopilot, endCompare, closeCommit, clearFocus, nothing +} + +public func graphBack(showCI: Bool, showAutopilot: Bool, comparing: Bool, selected: Bool, focused: Bool) -> GraphBack { + if showCI { return .closeCI } + if showAutopilot { return .closeAutopilot } + if comparing { return .endCompare } + if selected { return .closeCommit } + if focused { return .clearFocus } + return .nothing +} + +/// Whether a click on a commit closes its panel rather than opening one: +/// the commit already picked, clicked again without shift and with no +/// comparison open. +public func pickCloses(_ hash: String, selected: String?, shift: Bool, comparing: Bool) -> Bool { + !shift && !comparing && selected == hash +} diff --git a/macos/Tests/ConchKitTests/BranchGraphTests.swift b/macos/Tests/ConchKitTests/BranchGraphTests.swift index fefd0bb6..511ea3b5 100644 --- a/macos/Tests/ConchKitTests/BranchGraphTests.swift +++ b/macos/Tests/ConchKitTests/BranchGraphTests.swift @@ -171,3 +171,22 @@ func history() -> [LogCommit] { #expect(by["merging"]?.stopped == false) #expect(branchWorktree(project, "stopped")?.path == "/w/a") } + +// One step back at a time, the newest first, until nothing is open (#250 +// left the commit panel with no way to close it). +@Test func graphBackSteps() { + #expect(graphBack(showCI: true, showAutopilot: false, comparing: true, selected: true, focused: true) == .closeCI) + #expect(graphBack(showCI: false, showAutopilot: true, comparing: true, selected: true, focused: true) == .closeAutopilot) + #expect(graphBack(showCI: false, showAutopilot: false, comparing: true, selected: true, focused: true) == .endCompare) + #expect(graphBack(showCI: false, showAutopilot: false, comparing: false, selected: true, focused: true) == .closeCommit) + #expect(graphBack(showCI: false, showAutopilot: false, comparing: false, selected: false, focused: true) == .clearFocus) + #expect(graphBack(showCI: false, showAutopilot: false, comparing: false, selected: false, focused: false) == .nothing) +} + +@Test func clickingThePickedCommitClosesIt() { + #expect(pickCloses("a", selected: "a", shift: false, comparing: false)) + #expect(!pickCloses("b", selected: "a", shift: false, comparing: false)) + #expect(!pickCloses("a", selected: nil, shift: false, comparing: false)) + #expect(!pickCloses("a", selected: "a", shift: true, comparing: false)) // shift compares + #expect(!pickCloses("a", selected: "a", shift: false, comparing: true)) // ends a comparison instead +}