8bb68af9d435fe8326b476d8ee621f9f0e549fcb
- Author
- Ayman Bagabas <ayman.bagabas@gmail.com>
- Committer
- Ayman Bagabas <ayman.bagabas@gmail.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/ui/pages/selection/selection.go b/ui/pages/selection/selection.go
2index c0957fcdd9c3dff3519e2587a476903170731515..d2c46b1bd37ec6934ace27d6193d8688993cb9a9 100644
3--- a/ui/pages/selection/selection.go
4+++ b/ui/pages/selection/selection.go
5@@ -82,7 +82,7 @@ func (s *Selection) getMargins() (wm, hm int) {
6 wm = 0
7 hm = s.common.Styles.Tabs.GetVerticalFrameSize() +
8 s.common.Styles.Tabs.GetHeight()
9- if s.activePane == selectorPane && s.FilterState() == list.Filtering {
10+ if s.activePane == selectorPane && s.IsFiltering() {
11 // hide tabs when filtering
12 hm = 0
13 }
14@@ -103,6 +103,11 @@ func (s *Selection) SetSize(width, height int) {
15 s.readme.SetSize(width-wm, height-hm-1) // -1 for readme status line
16 }
17
18+// IsFiltering returns true if the selector is currently filtering.
19+func (s *Selection) IsFiltering() bool {
20+ return s.FilterState() == list.Filtering
21+}
22+
23 // ShortHelp implements help.KeyMap.
24 func (s *Selection) ShortHelp() []key.Binding {
25 k := s.selector.KeyMap
26@@ -126,49 +131,54 @@ func (s *Selection) ShortHelp() []key.Binding {
27
28 // FullHelp implements help.KeyMap.
29 func (s *Selection) FullHelp() [][]key.Binding {
30+ b := [][]key.Binding{
31+ {
32+ s.common.KeyMap.Section,
33+ },
34+ }
35 switch s.activePane {
36 case readmePane:
37 k := s.readme.KeyMap
38- return [][]key.Binding{
39- {
40- k.PageDown,
41- k.PageUp,
42- },
43- {
44- k.HalfPageDown,
45- k.HalfPageUp,
46- },
47- {
48- k.Down,
49- k.Up,
50- },
51- }
52+ b = append(b, []key.Binding{
53+ k.PageDown,
54+ k.PageUp,
55+ })
56+ b = append(b, []key.Binding{
57+ k.HalfPageDown,
58+ k.HalfPageUp,
59+ })
60+ b = append(b, []key.Binding{
61+ k.Down,
62+ k.Up,
63+ })
64 case selectorPane:
65 copyKey := s.common.KeyMap.Copy
66 copyKey.SetHelp("c", "copy command")
67 k := s.selector.KeyMap
68- return [][]key.Binding{
69- {
70+ if !s.IsFiltering() {
71+ b[0] = append(b[0],
72 s.common.KeyMap.Select,
73 copyKey,
74- k.CursorUp,
75- k.CursorDown,
76- },
77- {
78- k.NextPage,
79- k.PrevPage,
80- k.GoToStart,
81- k.GoToEnd,
82- },
83- {
84- k.Filter,
85- k.ClearFilter,
86- k.CancelWhileFiltering,
87- k.AcceptWhileFiltering,
88- },
89+ )
90 }
91+ b = append(b, []key.Binding{
92+ k.CursorUp,
93+ k.CursorDown,
94+ })
95+ b = append(b, []key.Binding{
96+ k.NextPage,
97+ k.PrevPage,
98+ k.GoToStart,
99+ k.GoToEnd,
100+ })
101+ b = append(b, []key.Binding{
102+ k.Filter,
103+ k.ClearFilter,
104+ k.CancelWhileFiltering,
105diff --git a/ui/ui.go b/ui/ui.go
106index 3f18e577e55bcc60ebc1ec45ea200c2bd93ed194..7e479df2d93737a783ea6a2255c5c5f211c22689 100644
107--- a/ui/ui.go
108+++ b/ui/ui.go
109@@ -95,10 +95,10 @@ func (ui *UI) ShortHelp() []key.Binding {
110 case loadedState:
111 b = append(b, ui.pages[ui.activePage].ShortHelp()...)
112 }
113- b = append(b,
114- ui.common.KeyMap.Quit,
115- ui.common.KeyMap.Help,
116- )
117+ if !ui.IsFiltering() {
118+ b = append(b, ui.common.KeyMap.Quit)
119+ }
120+ b = append(b, ui.common.KeyMap.Help)
121 return b
122 }
123
124@@ -111,10 +111,13 @@ func (ui *UI) FullHelp() [][]key.Binding {
125 case loadedState:
126 b = append(b, ui.pages[ui.activePage].FullHelp()...)
127 }
128- b = append(b, []key.Binding{
129- ui.common.KeyMap.Quit,
130+ h := []key.Binding{
131 ui.common.KeyMap.Help,
132- })
133+ }
134+ if !ui.IsFiltering() {
135+ h = append(h, ui.common.KeyMap.Quit)
136+ }
137+ b = append(b, h)
138 return b
139 }
140
141@@ -156,6 +159,16 @@ func (ui *UI) Init() tea.Cmd {
142 return tea.Batch(cmds...)
143 }
144
145+// IsFiltering returns true if the selection page is filtering.
146+func (ui *UI) IsFiltering() bool {
147+ if ui.activePage == selectionPage {
148+ if s, ok := ui.pages[selectionPage].(*selection.Selection); ok && s.FilterState() == list.Filtering {
149+ return true
150+ }
151+ }
152+ return false
153+}
154+
155 // Update implements tea.Model.
156 func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
157 cmds := make([]tea.Cmd, 0)
158@@ -181,13 +194,7 @@ func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
159 case key.Matches(msg, ui.common.KeyMap.Help):
160 cmds = append(cmds, footer.ToggleFooterCmd)
161 case key.Matches(msg, ui.common.KeyMap.Quit):
162- switch {
163- case ui.activePage == selectionPage:
164- if s, ok := ui.pages[selectionPage].(*selection.Selection); ok && s.FilterState() == list.Filtering {
165- break
166- }
167- fallthrough
168- default:
169+ if !ui.IsFiltering() {
170 // Stop bubblezone background workers.
171 ui.common.Zone.Close()
172 return ui, tea.Quit