j-morano / buffer_manager.nvim

A simple plugin to easily manage Neovim buffers.
MIT License
232 stars 12 forks source link

Manually deleting buffers breaks the marks list #27

Closed alek3y closed 1 year ago

alek3y commented 1 year ago

Steps to reproduce:

  1. nvim A B
  2. :bd on A
  3. Open the quick menu
  4. Write down A and press Enter

From some debugging I found the flow of the program during the last step to be:

  1. on_menu_save is called to update the marks (likely inside toggle_quick_menu because of the BufLeave event)
  2. Inside of it set_mark_list runs vim.fn.bufnr("A") which returns 1 instead of -1 despite not being on the list
  3. update_buffers is called which doesn't delete nor bdadds the A buffer back (because bufnr is not -1)
  4. select_menu_item starts nav_file which runs update_marks
  5. Inside of it remove_mark(1) is executed because buffer_is_valid returns false (since vim.fn.buflisted(1) returns 0 because it wasn't bdadded) which effectively undos the last step

This problem could be avoided by simply using :bw instead of :bd, as the help page mention it doesn't completely delete the buffer, however I think there should be a way to detect if the buffer is nobuflisted (which seems to be the option set on the buffer after :bd).

This was a little hard to dig out so I hope I got everything right.

j-morano commented 1 year ago

Hello. Thank you very much for the feedback, and for doing most of the work by debugging the code. I added a commit that fixes this issue. However, please check if it is working as intended, and feel free if to reopen it if it is not.

alek3y commented 1 year ago

Yes, it seems to work as expected. Thanks!