fix: rename and small lint/bug fix and dedupe add

This commit is contained in:
mpaulson 2023-11-03 18:09:20 -06:00
parent c1f49fef43
commit 734d10bc6d
3 changed files with 22 additions and 7 deletions

View File

@ -1,10 +1,19 @@
-- TODO: Define the config object
local function index_of(config, items, element)
local index = -1
for i, item in ipairs(items) do
if config.equals(element, item) then
index = i
break
end
end
return index
end
--- @class HarpoonItem
--- @field value string
--- @field context any
--- create a table object to be new'd
--- @class HarpoonList
--- @field config HarpoonPartialConfigItem
--- @field name string
@ -21,14 +30,19 @@ function HarpoonList:new(config, name, items)
end
---@return HarpoonList
function HarpoonList:push(item)
function HarpoonList:append(item)
item = item or self.config.add()
local index = index_of(self.config, self.items, item)
if index == -1 then
table.insert(self.items, item)
end
return self
end
---@return HarpoonList
function HarpoonList:addToFront(item)
function HarpoonList:prepend(item)
item = item or self.config.add()
table.insert(self.items, 1, item)
return self

View File

@ -29,7 +29,7 @@ describe("harpoon", function()
})
vim.api.nvim_win_set_cursor(0, {row, col})
local list = harpoon:list():push()
local list = harpoon:list():append()
harpoon:sync()
eq(harpoon:dump(), {

View File

@ -21,8 +21,9 @@ describe("list", function()
end
}
})
local list_config = Config.get_config(config, "foo")
local list = List.decode(config, "foo", {"foo:bar", "baz:qux"})
local list = List.decode(list_config, "foo", {"foo:bar", "baz:qux"})
local displayed = list:display()
eq(displayed, {