From 2ecdac84053d287849c42d1aafc5ba0481816094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Thu, 25 Apr 2024 23:10:01 +0200 Subject: [PATCH] action: tab: Release mouse press in case of mouse release while not pressed --- internal/action/bufpane.go | 5 +++++ internal/action/tab.go | 31 +++++++++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index e110eac7..ff83360c 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -500,12 +500,17 @@ func (h *BufPane) HandleEvent(event tcell.Event) { // Mouse event with no click - mouse was just released. // If there were multiple mouse buttons pressed, we don't know which one // was actually released, so we assume they all were released. + pressed := len(h.mousePressed) > 0 for me := range h.mousePressed { delete(h.mousePressed, me) me.state = MouseRelease h.DoMouseEvent(me, e) } + if !pressed { + // Propagate the mouse release in case the press wasn't for this BufPane + Tabs.ResetMouse() + } } } h.Buf.MergeCursors() diff --git a/internal/action/tab.go b/internal/action/tab.go index 19189e6e..061bfbb9 100644 --- a/internal/action/tab.go +++ b/internal/action/tab.go @@ -166,6 +166,22 @@ func (t *TabList) SetActive(a int) { } } +// ResetMouse resets the mouse release state after the screen was stopped +// or the pane changed. +// This prevents situations in which mouse releases are received at the wrong place +// and the mouse state is still pressed. +func (t *TabList) ResetMouse() { + for _, tab := range t.List { + tab.release = true + + for _, p := range tab.Panes { + if bp, ok := p.(*BufPane); ok { + bp.resetMouse() + } + } + } +} + // Tabs is the global tab list var Tabs *TabList @@ -184,20 +200,7 @@ func InitTabs(bufs []*buffer.Buffer) { } } - screen.RestartCallback = func() { - // The mouse could be released after the screen was stopped, so that - // we couldn't catch the mouse release event and would erroneously think - // that it is still pressed. So need to reset the mouse release state - // after the screen is restarted. - for _, t := range Tabs.List { - t.release = true - for _, p := range t.Panes { - if bp, ok := p.(*BufPane); ok { - bp.resetMouse() - } - } - } - } + screen.RestartCallback = Tabs.ResetMouse } func MainTab() *Tab {