ThePrimeagen/harpoon

[Harpoon 2] Duplicate list items cause all following list items to be deleted

Opened this issue · 5 comments

Steps to reproduce

  1. Mark a file
  2. Go to a different file
  3. Create a duplicate of the list item and then select it from the UI by hitting <CR>
    image
  4. Open UI again and select first item (now the file is opened)

I would expect this to take me to README.md on step 3, but it does not. I go to my back to the current file.

Logs

config_default#create_list_item README.md
HarpoonList:append { index = -1, item = { context = { col = 6, row = 1 }, value = "README.md" } }
ui#toggle_quick_menu#opening __harpoon_files
select by keymap '' <-- Does not work here
ui#select_menu_item selecting item 2 from { "README.md", "README.md" } options
ui#close_menu name: __harpoon_files win and bufnr { bufnr = 17, win = 1010 }
toggle by BufLeave
ui#toggle_quick_menu#closing
ui#save { "README.md", "README.md" }
ui#toggle_quick_menu#opening __harpoon_files <-- open up UI for second time
select by keymap '' <-- Works this time
ui#select_menu_item selecting item 1 from { "README.md" } options
ui#close_menu name: __harpoon_files win and bufnr { bufnr = 11, win = 1005 }
toggle by BufLeave
ui#toggle_quick_menu#closing
ui#save { "README.md" }
config_default#select { context = { col = 31, row = 7 }, value = "README.md" } __harpoon_files

Deletes items after the first duplicate

Steps to Reproduce

Same as above, but there is another list item already. So when hitting <CR>, the list looks like:

1 README.MD
2 README.MD
3 file1.txt

and my cursor is on the second README.md.
When I open the list back up, the list looks like:

1 README.MD

Logs 2

ui#toggle_quick_menu#opening __harpoon_files
select by keymap ''
ui#select_menu_item selecting item 2 from { "README.md", "README.md", "file1.txt" } options
ui#close_menu name: __harpoon_files win and bufnr { bufnr = 4, win = 1002 }
toggle by BufLeave
ui#toggle_quick_menu#closing
ui#save { "README.md", "README.md", "file1.txt" }
config_default#create_list_item file1.txt
ui#toggle_quick_menu#opening __harpoon_files
select by keymap ''
ui#select_menu_item selecting item 1 from { "README.md" } options
ui#close_menu name: __harpoon_files win and bufnr { bufnr = 6, win = 1003 }
toggle by BufLeave
ui#toggle_quick_menu#closing
ui#save { "README.md" }
config_default#select { context = { col = 32, row = 7 }, value = "README.md" } __harpoon_files

This issue seems to be related to PR #573. Duplicate items are turned into blank-lines (nil-items), which then trigger the issue, that's addressed in the PR.

Duplicates are not allowed

I'm going to have to think about how to solve this.

We most certainly cannot have duplicate items

@ThePrimeagen Does that go for empty lines also? In which case there would only be a single blank line left; or none, if they're not allowed?!

Blank should be fine which should make this fix easy

Next week I should get another 4 hours on harpoon, finish this off