diff --git a/tui/pages/common/back.go b/tui/pages/common/back.go index ec358e3..ed7565b 100644 --- a/tui/pages/common/back.go +++ b/tui/pages/common/back.go @@ -7,12 +7,13 @@ import ( func (m *Model) Back() (*Model, []tea.Cmd) { var cmds []tea.Cmd - m.ClearContextToStop() - - m.RestorePreviousKeys() - cmdView := m.RestorePreviousView() - - cmds = append(cmds, cmdView) + if len(m.contextToStop) > 0 { + m.ClearContextToStop() + } else { + m.RestorePreviousKeys() + cmdView := m.RestorePreviousView() + cmds = append(cmds, cmdView) + } return m, cmds } diff --git a/tui/pages/common/pages.go b/tui/pages/common/pages.go index b60569a..68f6b67 100644 --- a/tui/pages/common/pages.go +++ b/tui/pages/common/pages.go @@ -81,7 +81,7 @@ func BeanPages() map[PageID]*Page { errorP := &Page{ Keys: errorKeys, - previousPage: PRoot, + previousPage: PActual, } pages[PRoot] = root @@ -98,11 +98,13 @@ func BeanPages() map[PageID]*Page { // RestorePreviousKeys restore the keys. func (m *Model) RestorePreviousKeys() tea.Cmd { + *m.keys = *m.pages[PRoot].Keys + if _, ok := m.pages[m.viewName]; ok { previousPage := m.pages[m.viewName].previousPage - *m.keys = *m.pages[previousPage].Keys - } else { - *m.keys = *m.pages[PRoot].Keys + if m.pages[previousPage].Keys != nil { + *m.keys = *m.pages[previousPage].Keys + } } return nil }