Skip to content

Commit

Permalink
fix(api): on_close & keep_open not working as documented
Browse files Browse the repository at this point in the history
ref #936
  • Loading branch information
tomasklaen committed Sep 3, 2024
1 parent da83afd commit e4e8f07
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/uosc/lib/menus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ function open_command_menu(data, opts)
local menu

local function run_command(command)
if type(command) == 'string' then
mp.command(command)
else
if type(command) == 'table' then
---@diagnostic disable-next-line: deprecated
mp.commandv(unpack(command))
else
mp.command(tostring(command))
end
end

Expand All @@ -20,7 +20,11 @@ function open_command_menu(data, opts)
mp.commandv(unpack(itable_join({'script-message-to'}, menu.root.callback, {utils.format_json(event)})))
elseif event.type == 'activate' then
run_command(event.value)
menu:close()
-- Convention: Only pure item activations should close the menu.
-- Using modifiers or triggering item actions should not.
if not event.keep_open and not event.modifiers and not event.action then
menu:request_close()
end
end
end

Expand Down
1 change: 1 addition & 0 deletions src/uosc/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,7 @@ Manager = {
---@param element_ids string|string[]|nil `foo,bar` or `{'foo', 'bar'}`.
function Manager:disable(client, element_ids)
self._disabled_by[client] = comma_split(element_ids)
---@diagnostic disable-next-line: deprecated
self.disabled = create_set(itable_join(unpack(table_values(self._disabled_by))))
self:_commit()
end
Expand Down

0 comments on commit e4e8f07

Please sign in to comment.