Skip to content

Commit 013c2bf

Browse files
author
Anatoly Rugalev
committed
fix(ui): fix popup ESC key and add popup mutex
1 parent 9077b06 commit 013c2bf

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

app/ui/resourceMenu/resource_picker.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func newResourcePicker(container commander.ResourceContainer, f GroupKindFunc) (
3838
}, true))
3939
resMap[res.Gk.String()] = res
4040
}
41-
lt := listTable.NewStaticListTable(columns, rows, listTable.NoHorizontalScroll|listTable.WithFilter|listTable.WithHeaders|listTable.StartFilter, container.ScreenHandler())
41+
lt := listTable.NewStaticListTable(columns, rows, listTable.NoHorizontalScroll|listTable.WithFilter|listTable.WithHeaders|listTable.AlwaysFilter, container.ScreenHandler())
4242
lt.BindOnKeyPress(func(row commander.Row, event *tcell.EventKey) bool {
4343
if row == nil {
4444
return false

app/ui/resources/namespace/namespace_picker.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func PickNamespace(workspace commander.Workspace, resource *commander.Resource,
2222
}
2323

2424
func NewNamespacePicker(container commander.ResourceContainer, resource *commander.Resource, f NamespaceFunc) (*listTable.ResourceListTable, error) {
25-
rlt := listTable.NewResourceListTable(container, resource, listTable.NameOnly|listTable.NoActions|listTable.NoWatch|listTable.WithFilter|listTable.StartFilter)
25+
rlt := listTable.NewResourceListTable(container, resource, listTable.NameOnly|listTable.NoActions|listTable.NoWatch|listTable.WithFilter|listTable.AlwaysFilter)
2626
rlt.BindOnKeyPress(func(row commander.Row, event *tcell.EventKey) bool {
2727
if event.Key() == tcell.KeyEnter {
2828
go func() {

app/ui/widgets/listTable/listTable.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const (
4545
NoActions
4646
NoWatch
4747
WithFilter
48-
StartFilter
48+
AlwaysFilter
4949
)
5050

5151
func (tf TableFormat) Has(flag TableFormat) bool {
@@ -103,7 +103,7 @@ func NewListTable(prov commander.RowProvider, format TableFormat, screen command
103103
preloader: NewPreloader(screen),
104104
rowProvider: prov,
105105
screen: screen,
106-
filterMode: format.Has(StartFilter),
106+
filterMode: format.Has(AlwaysFilter),
107107
}
108108
lt.Render()
109109
return lt
@@ -294,7 +294,7 @@ func (lt *ListTable) BindOnChange(rowFunc RowFunc) {
294294
}
295295

296296
func (lt *ListTable) resetFilter() {
297-
lt.filterMode = lt.format.Has(StartFilter)
297+
lt.filterMode = lt.format.Has(AlwaysFilter)
298298
lt.filter = ""
299299
lt.Render()
300300
lt.reindexSelection()
@@ -589,7 +589,7 @@ func (lt *ListTable) HandleEvent(ev tcell.Event) bool {
589589
return true
590590
}
591591
if lt.format.Has(WithFilter) {
592-
if (lt.filterMode || lt.filter != "") && ev.Key() == tcell.KeyEsc && lt.IsFocused() {
592+
if (lt.filterMode || lt.filter != "") && ev.Key() == tcell.KeyEsc && lt.IsFocused() && !lt.format.Has(AlwaysFilter) {
593593
lt.resetFilter()
594594
return true
595595
}
@@ -603,7 +603,7 @@ func (lt *ListTable) HandleEvent(ev tcell.Event) bool {
603603
}
604604
return true
605605
case tcell.KeyEnter:
606-
if !lt.format.Has(StartFilter) {
606+
if !lt.format.Has(AlwaysFilter) {
607607
lt.filterMode = false
608608
lt.Render()
609609
lt.reindexSelection()

app/ui/workspace/workspace.go

+20-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/gdamore/tcell"
1313
"github.com/gdamore/tcell/views"
1414
"k8s.io/apimachinery/pkg/runtime/schema"
15+
"sync"
1516
)
1617

1718
type workspace struct {
@@ -22,9 +23,10 @@ type workspace struct {
2223
container commander.Container
2324
focus commander.FocusManager
2425

25-
popup commander.Popup
26-
menu *resourceMenu.ResourceMenu
27-
widget commander.Widget
26+
popupMu sync.Mutex
27+
popup commander.Popup
28+
menu *resourceMenu.ResourceMenu
29+
widget commander.Widget
2830

2931
namespace string
3032
namespaceResource *commander.Resource
@@ -34,10 +36,12 @@ type workspace struct {
3436

3537
func (w *workspace) Resize() {
3638
w.BoxLayout.Resize()
39+
w.popupMu.Lock()
3740
if w.popup != nil {
3841
w.popup.Reposition(w.view)
3942
w.popup.Resize()
4043
}
44+
w.popupMu.Unlock()
4145
}
4246

4347
func (w *workspace) SetView(view views.View) {
@@ -93,21 +97,27 @@ func (w *workspace) FocusManager() commander.FocusManager {
9397
}
9498

9599
func (w *workspace) ShowPopup(title string, widget commander.MaxSizeWidget) {
100+
w.popupMu.Lock()
96101
w.popup = popup.NewPopup(w.view, w.Theme(), title, widget, func() {
102+
w.popupMu.Lock()
97103
w.popup.OnHide()
98104
w.popup = nil
105+
w.popupMu.Unlock()
99106
w.UpdateScreen()
100107
})
101108
w.popup.OnShow()
102109
w.focus.Focus(w.popup)
110+
w.popupMu.Unlock()
103111
w.UpdateScreen()
104112
}
105113

106114
func (w *workspace) UpdateScreen() {
115+
w.popupMu.Lock()
107116
if w.popup != nil {
108117
w.popup.Reposition(w.container.Screen().View())
109118
w.popup.Resize()
110119
}
120+
w.popupMu.Unlock()
111121
if screen := w.container.Screen(); screen != nil {
112122
screen.UpdateScreen()
113123
}
@@ -131,19 +141,24 @@ func (w *workspace) Status() commander.StatusReporter {
131141

132142
func (w *workspace) Draw() {
133143
w.BoxLayout.Draw()
144+
w.popupMu.Lock()
134145
if w.popup != nil {
135146
w.popup.Draw()
136147
}
148+
w.popupMu.Unlock()
137149
}
138150

139151
func (w *workspace) HandleEvent(e tcell.Event) bool {
140152
if w.Status().HandleEvent(e) {
141153
return true
142154
}
143-
if w.focus.HandleEvent(e, w.popup == nil) {
155+
w.popupMu.Lock()
156+
hasPopup := w.popup != nil
157+
w.popupMu.Unlock()
158+
if w.focus.HandleEvent(e, !hasPopup) {
144159
return true
145160
}
146-
if w.popup != nil {
161+
if hasPopup {
147162
return false
148163
}
149164
switch ev := e.(type) {

0 commit comments

Comments
 (0)