ThePrimeagen / harpoon

MIT License
7.2k stars 384 forks source link

(bug) Opening the quickmenu after starting vim from '~/' then `:cd` to a dir deletes the list at that path #553

Open Makaze opened 8 months ago

Makaze commented 8 months ago

WARNING If this is about Harpoon1, the issue will be closed. All support and everything of harpoon1 will be frozen on master until 4/20 or 6/9 and then harpoon2 will become master

Please use harpoon2 for branch

Steps:

  1. Open nvim from ~/some/path/
  2. Call harpoon:list():add() on a file
  3. Open the harpoon menu, see addition
  4. :cd (to home dir, or anything)
  5. Open harpoon menu, see nothing
  6. Close menu.
  7. :q!
  8. Reopen vim in same path
  9. Open harpoon menu, see nothing
ThePrimeagen commented 8 months ago

this is how it should have always worked in harpoon2

if you change your directory you create a new hash. if for whatever we have changed that, then its my fault i let bad behavior exist

If you wish to emulate that behavior, do this ( i haven't tested this, but it "should" work")

local cwd = vim.loop.cwd()
harpoon:setup({
    settings = { 
        key = function() return cwd end
    }
})

effectively, by executing cd, you have changed cwd in vim.loop.cwd() which is used to calculate which harpoon you are using.

so the script above takes the FIRST cwd and uses it as the permanent one

Makaze commented 8 months ago

I was able to confirm this bug actually only occurs with the home directory. All other directories work fine as you intended, but for some reason, :cd from within user home breaks it.

Demo, first normal, then starting from ~/:

asciicast

Normal experience:

Steps:

  1. Setup:
    cd
    mkdir folder1
    touch folder1/a.lua
    touch folder1/b.lua
    mkdir folder2
    touch folder2/c.lua
    cd folder1
    nvim a.lua
  2. Call harpoon:list():add() to add a.lua
  3. Open the harpoon menu, see addition
  4. :q!
  5. cd ~/folder2
    nvim c.lua
  6. Open harpoon menu, see nothing
  7. Call harpoon:list():add() to add c.lua
  8. :cd ~/folder1
  9. Open harpoon menu, see c.lua
  10. :q!
    cd ~/folder1
    nvim
  11. Open harpoon menu, see a.lua -- original contents were preserved

The Bug

Steps:

  1. Setup:
    cd
    mkdir folder1
    touch folder1/a.lua
    touch folder1/b.lua
    cd folder1
    nvim a.lua
  2. Call harpoon:list():add() to add a.lua
  3. Open the harpoon menu, see addition
  4. :q!
  5. cd
    nvim
  6. Open harpoon menu, see nothing
  7. :cd ~/folder1
  8. Open harpoon menu, see nothing
  9. :q!
    cd ~/folder1
    nvim
  10. Open harpoon menu, see nothing -- original contents were overwritten or cleared
ThePrimeagen commented 8 months ago

Ok this is what more interesting, let me double check this!!