diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2022-09-25 14:38:48 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-09-26 17:32:00 +0200 |
commit | 4c3565653ab504166f9b8ecc1a44f6aa17f9f6e6 (patch) | |
tree | 5b69362ed13f5067cb9a346c642e33339aa81335 /lib | |
parent | 978768bff66e5f98f8cbf63ee19dd91fc4ca2bf3 (diff) | |
download | aerc-4c3565653ab504166f9b8ecc1a44f6aa17f9f6e6.tar.gz |
textinput: prevent data race from debounce function
Protect access to fields in textinput. Concurrent access can happen in
the main event loop and the completion debounce function.
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ui/textinput.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go index 70dcb3f5..ce8ccc55 100644 --- a/lib/ui/textinput.go +++ b/lib/ui/textinput.go @@ -3,6 +3,7 @@ package ui import ( "math" "strings" + "sync" "time" "github.com/gdamore/tcell/v2" @@ -17,6 +18,7 @@ import ( type TextInput struct { Invalidatable + sync.Mutex cells int ctx *Context focus bool @@ -294,7 +296,9 @@ func (ti *TextInput) updateCompletions() { if ti.completeDebouncer == nil { ti.completeDebouncer = time.AfterFunc(ti.completeDelay, func() { defer logging.PanicHandler() + ti.Lock() ti.showCompletions() + ti.Unlock() }) } else { ti.completeDebouncer.Stop() @@ -321,6 +325,8 @@ func (ti *TextInput) OnFocusLost(onFocusLost func(ti *TextInput)) { } func (ti *TextInput) Event(event tcell.Event) bool { + ti.Lock() + defer ti.Unlock() if event, ok := event.(*tcell.EventKey); ok { switch event.Key() { case tcell.KeyBackspace, tcell.KeyBackspace2: |