Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fern may wrongly overwrites a non-fern buffer. #514

Closed
mityu opened this issue Nov 11, 2024 · 7 comments · Fixed by #516
Closed

Fern may wrongly overwrites a non-fern buffer. #514

mityu opened this issue Nov 11, 2024 · 7 comments · Fixed by #516
Labels
bug Something isn't working

Comments

@mityu
Copy link

mityu commented Nov 11, 2024

Problem

Fern wrongly overwrites a new, non-fern buffer in certain situation.

Reproduce steps

  • Prepare this repro.vim
set nocompatible

" Please modify this path.
set runtimepath^=~/.cache/vim/pack/minpac/opt/vim-fern/

autocmd VimEnter * ++once call timer_start(10, {-> s:repro()})

function s:repro() abort
  Fern /
  split
  enew
endfunction
  • Run Vim with vim -u repro.vim
  • The current buffer (bufnr must be 2) has a file tree display although it's a anonymous, non-fern buffer.

Environment

  • Vim 9.1.842
  • Neovim v0.11.0-dev-1108+g5a86360400

The cause of this bug

  1. At the split command at line 2 in s:repro function, fern's auto duplication feature will create new fern buffer and trigger asynchronous viewer draws. At this time, the draws are not done yet and the new buffer is empty.
+----------------------------------------+
|  bufnr:2                               |
|  bufname:fern://...                    |
+----------------------------------------+
|  bufnr:1                               |
|  bufname:fern://...                    |
+----------------------------------------+
  1. enew command at line 3 in s:repro function opens a new empty buffer. However, since enew reuse the current buffer if it's not modified, the current buffer will be a non-fern buffer with keeping its bufnr same to one that the previously created fern buffer had.
+----------------------------------------+
|  bufnr:2                               |
|  bufname:(anonymous)                   |
+----------------------------------------+
|  bufnr:1                               |
|  bufname:fern://...                    |
+----------------------------------------+
  1. Since the bufnr is same, fern.vim's drawer will draw its contents to current buffer though it's no longer a fern buffer.
+----------------------------------------+
|  bufnr:2                               |
|  bufname:(anonymous, wrongly written)  |
+----------------------------------------+
|  bufnr:1                               |
|  bufname:fern://...                    |
+----------------------------------------+

(EDIT: Fix buffer positions in figures)

@mityu
Copy link
Author

mityu commented Nov 11, 2024

Sample screenshot. Ran the reproduce steps on Vim.

image

@lambdalisue
Copy link
Owner

I'll check it after Vimconf. Let me know if I forget about this issue.

@lambdalisue lambdalisue added the bug Something isn't working label Nov 11, 2024
@lambdalisue lambdalisue pinned this issue Nov 11, 2024
@mityu
Copy link
Author

mityu commented Nov 11, 2024

OK 👍.

Please don't mind, I don't think this is a critical issue; this rarely happens and we can restore the previous buffer contents with undo ;).

@mityu
Copy link
Author

mityu commented Dec 7, 2024

@lambdalisue ping

@lambdalisue
Copy link
Owner

I could reproduce the issue but it seems a bit complicated...

@lambdalisue
Copy link
Owner

@mityu Could you try #516?

@lambdalisue lambdalisue removed the help wanted Extra attention is needed label Dec 7, 2024
@mityu
Copy link
Author

mityu commented Dec 7, 2024

Seems to be working really well 👍
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants