From 31613db7625254b97712d8a5dcca8d5a26b982e5 Mon Sep 17 00:00:00 2001 From: Amolith Date: Mon, 30 Mar 2026 09:11:08 -0600 Subject: [PATCH] Extract activateScreen helper in session The init-then-replay-size sequence was duplicated verbatim in both navigateBack and advance. Extract it into a single activateScreen method. --- internal/ui/session.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/internal/ui/session.go b/internal/ui/session.go index 7644d631b328351f20e4662c5544ae72bfe73e1e..0721ebd90d45cabedbcecc5ad728d945439bf53d 100644 --- a/internal/ui/session.go +++ b/internal/ui/session.go @@ -206,8 +206,7 @@ func (s Session) breadcrumb() string { } // navigateBack moves to the previous screen, or exits if already on -// the first screen. Sends the adjusted window size directly to the -// re-activated screen so it has correct dimensions immediately. +// the first screen. func (s Session) navigateBack() (tea.Model, tea.Cmd) { if s.cursor <= 0 { // On the first screen: back exits. @@ -215,19 +214,11 @@ func (s Session) navigateBack() (tea.Model, tea.Cmd) { return s, tea.Quit } s.cursor-- - cmd := s.screens[s.cursor].Init() - if s.lastSize != nil { - updated, sizeCmd := s.screens[s.cursor].Update(s.adjustedSizeMsg()) - s.screens[s.cursor] = updated - cmd = tea.Batch(cmd, sizeCmd) - } - return s, cmd + return s, s.activateScreen() } // advance moves to the next screen. If the current screen is the last // one, the flow is complete — the session marks itself done and quits. -// Sends the adjusted window size directly to the newly activated -// screen so it has correct dimensions immediately. func (s Session) advance() (tea.Model, tea.Cmd) { if s.cursor >= len(s.screens)-1 { // Last screen completed: flow is done. @@ -236,13 +227,20 @@ func (s Session) advance() (tea.Model, tea.Cmd) { return s, tea.Quit } s.cursor++ + return s, s.activateScreen() +} + +// activateScreen initialises the screen at the current cursor and +// sends it the adjusted window size so it has correct dimensions +// immediately. Used by both navigateBack and advance. +func (s Session) activateScreen() tea.Cmd { cmd := s.screens[s.cursor].Init() if s.lastSize != nil { updated, sizeCmd := s.screens[s.cursor].Update(s.adjustedSizeMsg()) s.screens[s.cursor] = updated cmd = tea.Batch(cmd, sizeCmd) } - return s, cmd + return cmd } // forwardToScreen sends a message to the active screen and updates it.