aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2021-12-29 16:00:53 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2021-12-29 16:00:53 +0100
commit88ed312f6b6af17788e2aa2d73ccfe51f66d89e7 (patch)
tree62c40fe991c00f0d127cab0807676399fef72994
parent8550049db81453ab2437a562b3d793a8a00f8275 (diff)
downloadlite-xl-88ed312f6b6af17788e2aa2d73ccfe51f66d89e7.tar.gz
lite-xl-88ed312f6b6af17788e2aa2d73ccfe51f66d89e7.zip
Fix NagView missing mouse events
-rw-r--r--data/core/nagview.lua35
1 files changed, 33 insertions, 2 deletions
diff --git a/data/core/nagview.lua b/data/core/nagview.lua
index 35ae9b43..fca6c306 100644
--- a/data/core/nagview.lua
+++ b/data/core/nagview.lua
@@ -104,13 +104,38 @@ function NagView:on_mouse_moved(mx, my, ...)
end
end
+-- Used to store saved value for RootView.on_view_mouse_pressed
+local on_view_mouse_pressed
+
+
+local function capture_mouse_pressed(nag_view)
+ -- RootView is loaded locally to avoid NagView and RootView being
+ -- mutually recursive
+ local RootView = require "core.rootview"
+ on_view_mouse_pressed = RootView.on_view_mouse_pressed
+ RootView.on_view_mouse_pressed = function(button, x, y, clicks)
+ local handled = NagView.on_mouse_pressed(nag_view, button, x, y, clicks)
+ return handled or on_view_mouse_pressed(button, x, y, clicks)
+ end
+end
+
+
+local function release_mouse_pressed()
+ local RootView = require "core.rootview"
+ if on_view_mouse_pressed then
+ RootView.on_view_mouse_pressed = on_view_mouse_pressed
+ on_view_mouse_pressed = nil
+ end
+end
+
+
function NagView:on_mouse_pressed(button, mx, my, clicks)
- if NagView.super.on_mouse_pressed(self, button, mx, my, clicks) then return end
+ if NagView.super.on_mouse_pressed(self, button, mx, my, clicks) then return true end
for i, _, x,y,w,h in self:each_option() do
if mx >= x and my >= y and mx < x + w and my < y + h then
self:change_hovered(i)
command.perform "dialog:select"
- break
+ return true
end
end
end
@@ -202,6 +227,12 @@ function NagView:next()
self.force_focus = self.message ~= nil
core.set_active_view(self.message ~= nil and self or
core.next_active_view or core.last_active_view)
+ if self.message ~= nil and self then
+ -- We add a hook to manage all the mouse_pressed events.
+ capture_mouse_pressed(self)
+ else
+ release_mouse_pressed()
+ end
end
function NagView:show(title, message, options, on_select)