harpoon icon indicating copy to clipboard operation
harpoon copied to clipboard

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

Open Makaze opened this issue 10 months ago • 3 comments

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

Makaze avatar Apr 04 '24 20:04 Makaze

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

ThePrimeagen avatar Apr 05 '24 00:04 ThePrimeagen

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
  1. Call harpoon:list():add() to add a.lua
  2. Open the harpoon menu, see addition
  3. :q!
cd ~/folder2
nvim c.lua
  1. Open harpoon menu, see nothing
  2. Call harpoon:list():add() to add c.lua
  3. :cd ~/folder1
  4. Open harpoon menu, see c.lua
  5. :q!
cd ~/folder1
nvim
  1. 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
  1. Call harpoon:list():add() to add a.lua
  2. Open the harpoon menu, see addition
  3. :q!
cd
nvim
  1. Open harpoon menu, see nothing
  2. :cd ~/folder1
  3. Open harpoon menu, see nothing
  4. :q!
cd ~/folder1
nvim
  1. Open harpoon menu, see nothing -- original contents were overwritten or cleared

Makaze avatar Apr 05 '24 02:04 Makaze

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

ThePrimeagen avatar Apr 05 '24 03:04 ThePrimeagen