Catch mouse clicks if `contextmenu` is open

Also disallow re-opening the `contextmenu` if it's already visible.
This commit is contained in:
Guldoman 2022-04-27 17:55:46 +02:00
parent 4934e741b3
commit 3950406750
No known key found for this signature in database
GPG Key ID: C08A498EC7F1AFDD
1 changed files with 12 additions and 10 deletions

View File

@ -171,19 +171,21 @@ function ContextMenu:call_selected_item()
end
function ContextMenu:on_mouse_pressed(button, px, py, clicks)
local selected = self:get_item_selected()
local caught = false
self:hide()
if button == "left" then
if selected then
self:on_selected(selected)
caught = true
if self.show_context_menu then
if button == "left" then
local selected = self:get_item_selected()
if selected then
self:on_selected(selected)
end
end
self:hide()
caught = true
else
if button == "right" then
caught = self:show(px, py)
end
end
if button == "right" then
caught = self:show(px, py)
end
return caught
end