mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-25 18:07:07 +09:00
Merge pull request #3271 from JoeKar/fix/inactive-mouse-release
Fix lost mouse release events in case the pane becomes inactive
This commit is contained in:
@@ -500,12 +500,17 @@ func (h *BufPane) HandleEvent(event tcell.Event) {
|
|||||||
// Mouse event with no click - mouse was just released.
|
// Mouse event with no click - mouse was just released.
|
||||||
// If there were multiple mouse buttons pressed, we don't know which one
|
// If there were multiple mouse buttons pressed, we don't know which one
|
||||||
// was actually released, so we assume they all were released.
|
// was actually released, so we assume they all were released.
|
||||||
|
pressed := len(h.mousePressed) > 0
|
||||||
for me := range h.mousePressed {
|
for me := range h.mousePressed {
|
||||||
delete(h.mousePressed, me)
|
delete(h.mousePressed, me)
|
||||||
|
|
||||||
me.state = MouseRelease
|
me.state = MouseRelease
|
||||||
h.DoMouseEvent(me, e)
|
h.DoMouseEvent(me, e)
|
||||||
}
|
}
|
||||||
|
if !pressed {
|
||||||
|
// Propagate the mouse release in case the press wasn't for this BufPane
|
||||||
|
Tabs.ResetMouse()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
h.Buf.MergeCursors()
|
h.Buf.MergeCursors()
|
||||||
|
|||||||
@@ -124,6 +124,12 @@ func (t *TabList) HandleEvent(event tcell.Event) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case tcell.ButtonNone:
|
||||||
|
if t.List[t.Active()].release {
|
||||||
|
// Mouse release received, while already released
|
||||||
|
t.ResetMouse()
|
||||||
|
return
|
||||||
|
}
|
||||||
case tcell.WheelUp:
|
case tcell.WheelUp:
|
||||||
if my == t.Y {
|
if my == t.Y {
|
||||||
t.Scroll(4)
|
t.Scroll(4)
|
||||||
@@ -166,6 +172,26 @@ 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 {
|
||||||
|
if !tab.release && tab.resizing != nil {
|
||||||
|
tab.resizing = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
tab.release = true
|
||||||
|
|
||||||
|
for _, p := range tab.Panes {
|
||||||
|
if bp, ok := p.(*BufPane); ok {
|
||||||
|
bp.resetMouse()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Tabs is the global tab list
|
// Tabs is the global tab list
|
||||||
var Tabs *TabList
|
var Tabs *TabList
|
||||||
|
|
||||||
@@ -184,20 +210,7 @@ func InitTabs(bufs []*buffer.Buffer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
screen.RestartCallback = func() {
|
screen.RestartCallback = Tabs.ResetMouse
|
||||||
// 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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func MainTab() *Tab {
|
func MainTab() *Tab {
|
||||||
|
|||||||
Reference in New Issue
Block a user