Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(list): disable quit keybinding while filtering #118

Merged
merged 1 commit into from Feb 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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