Skip to content

Commit 4764154

Browse files
committed
fix: app wasn't re-rendered in some cases
1 parent 6ed1996 commit 4764154

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

internal/app/app.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func (a *App) Close() {
172172
func (a *App) Loading(flag bool) {
173173
a.spinner.text = "Fetching"
174174
a.loading = flag
175-
a.dirty = true
175+
a.setDirty()
176176
}
177177

178178
func (a *App) IsLoading() bool {
@@ -190,7 +190,7 @@ func (a *App) LoadingWithText(flag bool, text string) {
190190

191191
func (a *App) SetView(view View) {
192192
a.viewMutex.Lock()
193-
a.dirty = true
193+
a.setDirty()
194194
if a.view != nil {
195195
a.view.Destroy()
196196
delete(a.keepAlive, a.view)
@@ -258,14 +258,14 @@ func (a *App) AddFlash(flash Drawable, duration time.Duration) {
258258
resizable.Resize(a.ScreenX, a.ScreenY)
259259
}
260260
timer := time.NewTimer(duration)
261-
a.dirty = true
261+
a.setDirty()
262262
go func() {
263263
defer a.PanicRecover()
264264
<-timer.C
265265
a.changeMutex.Lock()
266266
a.flash = nil // it could lead to removing just-added flash message. For now, it's a good-enough solution
267267
a.changeMutex.Unlock()
268-
a.dirty = true
268+
a.setDirty()
269269
}()
270270
}
271271

@@ -305,7 +305,7 @@ func (a *App) SetDirty() {
305305
}
306306

307307
func (a *App) ClearNow() {
308-
a.dirty = true
308+
a.setDirty()
309309
a.clear()
310310
// a.screen.Clear() is preserving terminal buffer (not alternate screen buffer) :/ different then in 1.3
311311
//a.screen.Clear()
@@ -329,6 +329,13 @@ func (a *App) PanicRecover() {
329329
}
330330
}
331331

332+
func (a *App) setDirty() {
333+
a.dirty = true
334+
a.RunOnAppRoutine(func() {
335+
a.dirty = true
336+
})
337+
}
338+
332339
func (a *App) clear() {
333340
a.changeMutex.Lock()
334341
a.drawables = nil
@@ -357,7 +364,7 @@ func (a *App) processTerminalEvents() {
357364
ev := a.screen.PollEvent()
358365
switch ev := ev.(type) {
359366
case *tcell.EventResize:
360-
a.dirty = true
367+
a.setDirty()
361368
a.screen.Sync()
362369
x, y := a.screen.Size()
363370
a.ScreenX = x
@@ -368,7 +375,7 @@ func (a *App) processTerminalEvents() {
368375
}
369376
}
370377
case *tcell.EventKey:
371-
a.dirty = true
378+
a.setDirty()
372379
if ev.Key() == tcell.KeyCtrlC {
373380
a.Quit()
374381
return

internal/app/fuzzy_find.go

+18-6
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (f *FuzzyFind) Update() {
144144
}
145145

146146
func (f *FuzzyFind) ForceUpdate() {
147-
f.dirty = true
147+
f.markAsDirty()
148148
f.Update()
149149
}
150150

@@ -153,7 +153,7 @@ func (f *FuzzyFind) HandleKeyEvent(ev *tcell.EventKey) {
153153
f.Complete <- FuzzyFindResult{Index: -1, Match: ""}
154154
}
155155
if ev.Key() == tcell.KeyEnter {
156-
f.dirty = true
156+
f.markAsDirty()
157157
f.Update()
158158
if len(f.matches) > 0 && f.selected >= 0 {
159159
match := f.matches[f.selected].Str
@@ -167,7 +167,7 @@ func (f *FuzzyFind) HandleKeyEvent(ev *tcell.EventKey) {
167167
if f.buffer.Len() > 0 {
168168
f.buffer.Truncate(f.buffer.Len() - 1)
169169
}
170-
f.dirty = true
170+
f.markAsDirty()
171171
}
172172
if ev.Key() == tcell.KeyUp || ev.Key() == tcell.KeyTab {
173173
f.selected = ClampInt(f.selected+1, 0, f.matches.Len()-1)
@@ -179,7 +179,7 @@ func (f *FuzzyFind) HandleKeyEvent(ev *tcell.EventKey) {
179179
}
180180
if f.isEventWritable(ev) {
181181
f.buffer.WriteRune(ev.Rune())
182-
f.dirty = true
182+
f.markAsDirty()
183183
}
184184
}
185185

@@ -194,7 +194,7 @@ func (f *FuzzyFind) GetQuery() string {
194194

195195
func (f *FuzzyFind) SetQuery(q string) {
196196
f.buffer.WriteString(q)
197-
f.dirty = true
197+
f.markAsDirty()
198198
}
199199

200200
func (f *FuzzyFind) AlwaysShowAllResults() {
@@ -260,7 +260,7 @@ func (f *FuzzyFind) updateRecordsFromSupplier() {
260260
Index: i,
261261
})
262262
}
263-
f.dirty = true
263+
f.markAsDirty()
264264
}
265265

266266
func (f *FuzzyFind) isEventWritable(ev *tcell.EventKey) bool {
@@ -270,6 +270,18 @@ func (f *FuzzyFind) isEventWritable(ev *tcell.EventKey) bool {
270270
ev.Rune() == '!'
271271
}
272272

273+
func (f *FuzzyFind) markAsDirty() {
274+
f.dirty = true
275+
// it couples fuzzyFinder with app ... which is not nice,
276+
// but it's the easy way to make sure that app is re-rendered
277+
// whenever fuzzy search is updated. Another solution would be to
278+
// expose dirty channel from here... and handle it from every place
279+
// which is using fuzzy finder. Let's stick to that one for a time being...
280+
GetApp().RunOnAppRoutine(func() {
281+
GetApp().SetDirty()
282+
})
283+
}
284+
273285
func contains(needle int, haystack []int) bool {
274286
for _, i := range haystack {
275287
if needle == i {

0 commit comments

Comments
 (0)