Skip to content

Commit

Permalink
Merge pull request #438 from mrjones2014/mrj/437/mini-pick-compatibility
Browse files Browse the repository at this point in the history
fix(api): Fix toolbox functions to work if items are deepcopied
  • Loading branch information
mrjones2014 authored Mar 22, 2024
2 parents ad4b0ad + 3b07f50 commit d2665ca
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions lua/legendary/toolbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,58 +84,54 @@ function M.vsplit_then(fn)
end
end

local function check_class(item, class)
return vim.tbl_get(item or {}, 'class', 'name') == class
end

---Check if an item is a Keymap
---@param keymap LegendaryItem
---@return boolean
function M.is_keymap(keymap)
-- inline require to avoid circular dependency
return keymap.class == require('legendary.data.keymap')
return check_class(keymap, 'Keymap')
end

---Check if an item is a Command
---@param cmd LegendaryItem
---@return boolean
function M.is_command(cmd)
-- inline require to avoid circular dependency
return cmd.class == require('legendary.data.command')
return check_class(cmd, 'Command')
end

---Check if an item is an Augroup
---@param au LegendaryItem
---@return boolean
function M.is_augroup(au)
-- inline require to avoid circular dependency
return au.class == require('legendary.data.augroup')
return check_class(au, 'Augroup')
end

---Check if an item is an Autocmd
---@param autocmd LegendaryItem
---@return boolean
function M.is_autocmd(autocmd)
-- inline require to avoid circular dependency
return autocmd.class == require('legendary.data.autocmd')
return check_class(autocmd, 'Autocmd')
end

---Check if an item is an Augroup or Autocmd
---@param au_or_autocmd LegendaryItem
---@return boolean
function M.is_augroup_or_autocmd(au_or_autocmd)
-- inline require to avoid circular dependency
return au_or_autocmd.class == require('legendary.data.augroup')
or au_or_autocmd.class == require('legendary.data.autocmd')
return M.is_autocmd(au_or_autocmd) or M.is_augroup(au_or_autocmd)
end

function M.is_itemgroup(group)
-- inline require to avoid circular dependency
return group.class == require('legendary.data.itemgroup')
return check_class(group, 'ItemGroup')
end

---Check if an item is a Function
---@param func LegendaryItem
---@return boolean
function M.is_function(func)
-- inline require to avoid circular dependency
return func.class == require('legendary.data.function')
return check_class(func, 'Function')
end

---Check if the given mode string indicates a visual mode or a sub-mode of visual mode.
Expand Down

0 comments on commit d2665ca

Please sign in to comment.