Skip to content

Commit

Permalink
fix(list): disable quit keybinding while filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenries authored and aymanbagabas committed Feb 8, 2022
1 parent 06358c3 commit 1d48925
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions list/list.go
Expand Up @@ -107,6 +107,8 @@ type Model struct {
// Key mappings for navigating the list.
KeyMap KeyMap

disableQuitKeybindings bool

// Additional key mappings for the short and full help views. This allows
// you to add additional key mappings to the help menu without
// re-implementing the help component. Of course, you can also disable the
Expand Down Expand Up @@ -521,6 +523,7 @@ func (m *Model) StopSpinner() {
// Helper for disabling the keybindings used for quitting, incase you want to
// handle this elsewhere in your application.
func (m *Model) DisableQuitKeybindings() {
m.disableQuitKeybindings = true
m.KeyMap.Quit.SetEnabled(false)
m.KeyMap.ForceQuit.SetEnabled(false)
}
Expand Down Expand Up @@ -591,7 +594,6 @@ func (m Model) itemsAsFilterItems() filteredItems {

// Set keybindings according to the filter state.
func (m *Model) updateKeybindings() {
quit := m.KeyMap.Quit.Enabled()
switch m.filterState {
case Filtering:
m.KeyMap.CursorUp.SetEnabled(false)
Expand Down Expand Up @@ -624,6 +626,7 @@ func (m *Model) updateKeybindings() {
m.KeyMap.ClearFilter.SetEnabled(m.filterState == FilterApplied)
m.KeyMap.CancelWhileFiltering.SetEnabled(false)
m.KeyMap.AcceptWhileFiltering.SetEnabled(false)
m.KeyMap.Quit.SetEnabled(!m.disableQuitKeybindings)

if m.Help.ShowAll {
m.KeyMap.ShowFullHelp.SetEnabled(true)
Expand All @@ -634,7 +637,6 @@ func (m *Model) updateKeybindings() {
m.KeyMap.CloseFullHelp.SetEnabled(minHelp)
}
}
m.KeyMap.Quit.SetEnabled(quit)
}

// Update pagination according to the amount of items for the current state.
Expand Down

0 comments on commit 1d48925

Please sign in to comment.