@@ -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.