diff --git a/lua/harpoon/list.lua b/lua/harpoon/list.lua index 897122fa..014c67cf 100644 --- a/lua/harpoon/list.lua +++ b/lua/harpoon/list.lua @@ -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 @@ -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) diff --git a/lua/harpoon/test/list_spec.lua b/lua/harpoon/test/list_spec.lua index 7adbbc39..79e1c01b 100644 --- a/lua/harpoon/test/list_spec.lua +++ b/lua/harpoon/test/list_spec.lua @@ -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)