Skip to content

Commit

Permalink
Merge pull request #628 from PedroBinotto/harpoon2
Browse files Browse the repository at this point in the history
[BUGFIX] Calling `remove_at` to manipulate elements when using Telescope UI causes items list to become malformed
  • Loading branch information
ThePrimeagen authored Feb 10, 2025
2 parents 09c6d04 + 0754d1c commit 7f5bb6f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 4 additions & 5 deletions lua/harpoon/list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ end
--- @return string[]
function HarpoonList:encode()
local out = {}
for _, v in ipairs(self.items) do
table.insert(out, self.config.encode(v))
for k, v in pairs(self.items) do
out[k] = self.config.encode(v)
end

return out
Expand All @@ -357,9 +357,8 @@ end
--- @param items string[]
function HarpoonList.decode(list_config, name, items)
local list_items = {}

for _, item in ipairs(items) do
table.insert(list_items, list_config.decode(item))
for k, item in pairs(items) do
list_items[k] = item ~= vim.NIL and list_config.decode(item) or nil
end

return HarpoonList:new(list_config, name, list_items)
Expand Down
7 changes: 6 additions & 1 deletion lua/harpoon/test/list_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ describe("list", function()
})
local list_config = Config.get_config(config, "foo")

local list = List.decode(list_config, "foo", { "foo:bar", "baz:qux" })
local list = List.decode(list_config, "foo", {
"foo:bar",
nil,
[3] = "baz:qux",
})
local displayed = list:display()

eq(displayed, {
"foo---bar",
"",
"baz---qux",
})
end)
Expand Down

0 comments on commit 7f5bb6f

Please sign in to comment.