compose: avoid double lock in MouseEvent

The MouseEvent locks the composer, and also calls FocusEditor which
attempts to lock the composer. This results in a deadlock.

No need to call FocusEditor which takes a name as parameter and needs to
iterate over all editors to find the correct one. We already have the
headerEditor object, use it directly.

Fixes: bf2bf8c242 ("compose: prevent out of bounds access")
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Signed-off-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Tim Culverhouse 2022-10-04 13:06:55 -05:00 committed by Robin Jarry
parent d99b6081f7
commit d2f4f12f66

View file

@ -618,10 +618,13 @@ func (c *Composer) MouseEvent(localX int, localY int, event tcell.Event) {
c.Lock() c.Lock()
defer c.Unlock() defer c.Unlock()
c.grid.MouseEvent(localX, localY, event) c.grid.MouseEvent(localX, localY, event)
for _, e := range c.focusable { for i, e := range c.focusable {
he, ok := e.(*headerEditor) he, ok := e.(*headerEditor)
if ok && he.focused { if ok && he.focused {
c.FocusEditor(he.name) c.focusable[c.focused].Focus(false)
c.focused = i
c.focusable[c.focused].Focus(true)
return
} }
} }
} }