Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Calling remove_at to manipulate elements when using Telescope UI causes items list to become malformed #628

Open
wants to merge 2 commits into
base: harpoon2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading