mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 10:00:29 +00:00
fix: rename and small lint/bug fix and dedupe add
This commit is contained in:
parent
c1f49fef43
commit
734d10bc6d
@ -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
|
--- @class HarpoonItem
|
||||||
--- @field value string
|
--- @field value string
|
||||||
--- @field context any
|
--- @field context any
|
||||||
|
|
||||||
--- create a table object to be new'd
|
|
||||||
--- @class HarpoonList
|
--- @class HarpoonList
|
||||||
--- @field config HarpoonPartialConfigItem
|
--- @field config HarpoonPartialConfigItem
|
||||||
--- @field name string
|
--- @field name string
|
||||||
@ -21,14 +30,19 @@ function HarpoonList:new(config, name, items)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@return HarpoonList
|
---@return HarpoonList
|
||||||
function HarpoonList:push(item)
|
function HarpoonList:append(item)
|
||||||
item = item or self.config.add()
|
item = item or self.config.add()
|
||||||
table.insert(self.items, item)
|
|
||||||
|
local index = index_of(self.config, self.items, item)
|
||||||
|
if index == -1 then
|
||||||
|
table.insert(self.items, item)
|
||||||
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return HarpoonList
|
---@return HarpoonList
|
||||||
function HarpoonList:addToFront(item)
|
function HarpoonList:prepend(item)
|
||||||
item = item or self.config.add()
|
item = item or self.config.add()
|
||||||
table.insert(self.items, 1, item)
|
table.insert(self.items, 1, item)
|
||||||
return self
|
return self
|
||||||
|
@ -29,7 +29,7 @@ describe("harpoon", function()
|
|||||||
})
|
})
|
||||||
vim.api.nvim_win_set_cursor(0, {row, col})
|
vim.api.nvim_win_set_cursor(0, {row, col})
|
||||||
|
|
||||||
local list = harpoon:list():push()
|
local list = harpoon:list():append()
|
||||||
harpoon:sync()
|
harpoon:sync()
|
||||||
|
|
||||||
eq(harpoon:dump(), {
|
eq(harpoon:dump(), {
|
||||||
|
@ -21,8 +21,9 @@ describe("list", function()
|
|||||||
end
|
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()
|
local displayed = list:display()
|
||||||
|
|
||||||
eq(displayed, {
|
eq(displayed, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user