Skip to content

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

Closed
@mityu

Description

@mityu

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions