From 22dbc83967ea0b1c34a65fba5e9341b576640774 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 13 Sep 2026 13:22:30 +0200 Subject: [PATCH] Ask for the panel beneath the focused main view in one place Two questions the pane answers from the panel beneath it each reach for it themselves, guard included. Opening a line in a pull request needs it twice more, for the branch and for the commit. Extract sidePanelBeneath, which is also where the guard against asking for the panel beneath an off-stack pane now belongs. Co-Authored-By: Claude Opus 5 (1M context) --- pkg/gui/controllers/main_view_controller.go | 26 +++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/pkg/gui/controllers/main_view_controller.go b/pkg/gui/controllers/main_view_controller.go index 3f0a1e849..6511562eb 100644 --- a/pkg/gui/controllers/main_view_controller.go +++ b/pkg/gui/controllers/main_view_controller.go @@ -319,17 +319,22 @@ func (self *MainViewController) isDiffView() bool { return self.diffMainViewType() != types.DiffMainViewTypeNone } +// sidePanelBeneath returns the side panel this pane is showing the content of, and nil +// when there is none. The IsInStack guard is essential: NextInStack panics for a context +// that isn't in the stack, and GetKeybindings (which leads here) also runs for off-stack +// panes — at startup and while generating the cheatsheets, where the stack is empty. +func (self *MainViewController) sidePanelBeneath() types.Context { + if !self.c.Context().IsInStack(self.context) { + return nil + } + return self.c.Context().NextInStack(self.context) +} + // diffMainViewType reports what the diff in the focused main view belongs to, taken // from the side panel beneath it, or DiffMainViewTypeNone when this pane isn't on the -// stack or has no diff panel beneath it. The IsInStack guard is essential: -// NextInStack panics for a context that isn't in the stack, and GetKeybindings (which -// leads here) also runs for off-stack panes — at startup and while generating the -// cheatsheets, where the stack is empty. +// stack or has no diff panel beneath it. func (self *MainViewController) diffMainViewType() types.DiffMainViewType { - if !self.c.Context().IsInStack(self.context) { - return types.DiffMainViewTypeNone - } - if diffContext, ok := self.c.Context().NextInStack(self.context).(types.DiffMainViewContext); ok { + if diffContext, ok := self.sidePanelBeneath().(types.DiffMainViewContext); ok { return diffContext.GetDiffMainViewType() } return types.DiffMainViewTypeNone @@ -339,10 +344,7 @@ func (self *MainViewController) diffMainViewType() types.DiffMainViewType { // hand out the diff it rendered there. nil when this pane isn't on the stack, or the // panel beneath shows no diff. func (self *MainViewController) diffSource() types.FocusedMainViewDiffSource { - if !self.c.Context().IsInStack(self.context) { - return nil - } - sidePanel := self.c.Context().NextInStack(self.context) + sidePanel := self.sidePanelBeneath() if sidePanel == nil { return nil }