Skip to content

Commit

Permalink
fix(ui): incorrect help while filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Nov 15, 2022
1 parent 8c40f69 commit 8bb68af
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 47 deletions.
76 changes: 43 additions & 33 deletions ui/pages/selection/selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *Selection) getMargins() (wm, hm int) {
wm = 0
hm = s.common.Styles.Tabs.GetVerticalFrameSize() +
s.common.Styles.Tabs.GetHeight()
if s.activePane == selectorPane && s.FilterState() == list.Filtering {
if s.activePane == selectorPane && s.IsFiltering() {
// hide tabs when filtering
hm = 0
}
Expand All @@ -103,6 +103,11 @@ func (s *Selection) SetSize(width, height int) {
s.readme.SetSize(width-wm, height-hm-1) // -1 for readme status line
}

// IsFiltering returns true if the selector is currently filtering.
func (s *Selection) IsFiltering() bool {
return s.FilterState() == list.Filtering
}

// ShortHelp implements help.KeyMap.
func (s *Selection) ShortHelp() []key.Binding {
k := s.selector.KeyMap
Expand All @@ -126,49 +131,54 @@ func (s *Selection) ShortHelp() []key.Binding {

// FullHelp implements help.KeyMap.
func (s *Selection) FullHelp() [][]key.Binding {
b := [][]key.Binding{
{
s.common.KeyMap.Section,
},
}
switch s.activePane {
case readmePane:
k := s.readme.KeyMap
return [][]key.Binding{
{
k.PageDown,
k.PageUp,
},
{
k.HalfPageDown,
k.HalfPageUp,
},
{
k.Down,
k.Up,
},
}
b = append(b, []key.Binding{
k.PageDown,
k.PageUp,
})
b = append(b, []key.Binding{
k.HalfPageDown,
k.HalfPageUp,
})
b = append(b, []key.Binding{
k.Down,
k.Up,
})
case selectorPane:
copyKey := s.common.KeyMap.Copy
copyKey.SetHelp("c", "copy command")
k := s.selector.KeyMap
return [][]key.Binding{
{
if !s.IsFiltering() {
b[0] = append(b[0],
s.common.KeyMap.Select,
copyKey,
k.CursorUp,
k.CursorDown,
},
{
k.NextPage,
k.PrevPage,
k.GoToStart,
k.GoToEnd,
},
{
k.Filter,
k.ClearFilter,
k.CancelWhileFiltering,
k.AcceptWhileFiltering,
},
)
}
b = append(b, []key.Binding{
k.CursorUp,
k.CursorDown,
})
b = append(b, []key.Binding{
k.NextPage,
k.PrevPage,
k.GoToStart,
k.GoToEnd,
})
b = append(b, []key.Binding{
k.Filter,
k.ClearFilter,
k.CancelWhileFiltering,
k.AcceptWhileFiltering,
})
}
return [][]key.Binding{}
return b
}

// Init implements tea.Model.
Expand Down
35 changes: 21 additions & 14 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ func (ui *UI) ShortHelp() []key.Binding {
case loadedState:
b = append(b, ui.pages[ui.activePage].ShortHelp()...)
}
b = append(b,
ui.common.KeyMap.Quit,
ui.common.KeyMap.Help,
)
if !ui.IsFiltering() {
b = append(b, ui.common.KeyMap.Quit)
}
b = append(b, ui.common.KeyMap.Help)
return b
}

Expand All @@ -111,10 +111,13 @@ func (ui *UI) FullHelp() [][]key.Binding {
case loadedState:
b = append(b, ui.pages[ui.activePage].FullHelp()...)
}
b = append(b, []key.Binding{
ui.common.KeyMap.Quit,
h := []key.Binding{
ui.common.KeyMap.Help,
})
}
if !ui.IsFiltering() {
h = append(h, ui.common.KeyMap.Quit)
}
b = append(b, h)
return b
}

Expand Down Expand Up @@ -156,6 +159,16 @@ func (ui *UI) Init() tea.Cmd {
return tea.Batch(cmds...)
}

// IsFiltering returns true if the selection page is filtering.
func (ui *UI) IsFiltering() bool {
if ui.activePage == selectionPage {
if s, ok := ui.pages[selectionPage].(*selection.Selection); ok && s.FilterState() == list.Filtering {
return true
}
}
return false
}

// Update implements tea.Model.
func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmds := make([]tea.Cmd, 0)
Expand All @@ -181,13 +194,7 @@ func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, ui.common.KeyMap.Help):
cmds = append(cmds, footer.ToggleFooterCmd)
case key.Matches(msg, ui.common.KeyMap.Quit):
switch {
case ui.activePage == selectionPage:
if s, ok := ui.pages[selectionPage].(*selection.Selection); ok && s.FilterState() == list.Filtering {
break
}
fallthrough
default:
if !ui.IsFiltering() {
// Stop bubblezone background workers.
ui.common.Zone.Close()
return ui, tea.Quit
Expand Down

0 comments on commit 8bb68af

Please sign in to comment.