Skip to content

Conversation

@Gelio
Copy link
Contributor

@Gelio Gelio commented Jul 3, 2022

With actions.open_file enabled, when an NvimTree buffer is changed to some other buffer, the window in which that buffer swap occurs is closed.

Since the quit_on_open function runs on NvimTree BufWipeout, there should not be a need to close the window that holds that buffer. Looking at the code, it seemed sensible to not to call _prevent_buffer_override if quit_on_open is enabled, since at best it's a no-op, and at worst it will accidentally modify the window layout.

This issue could be reproduced by:

  1. Opening an existing file :e firstfile.txt
  2. :vs
  3. :lua require("nvim-tree").open_replacing_current_buffer()
  4. Replacing the NvimTree buffer with some other buffer by
    :e somefile.txt

The window containing the buffer opened in the first step would be closed. There would be only a single window with somefile.txt on that tab page.

Peek.2022-07-03.12-44-failed.mp4

With this fix, that window is retained and the tab now contains firstfile.txt in the left window and somefile.txt in the right
window.

Peek.2022-07-03.12-44.mp4

With `actions.open_file` enabled, when an NvimTree buffer is changed to
some other buffer, the window in which that buffer swap occurs is
closed.

Since the `quit_on_open` function runs on `NvimTree` `BufWipeout`, there
should not be a need to close the window that holds that buffer.

This issue could be reproduced by:

1. Opening an existing file `:e firstfile.txt`
2. `:sp`
3. `:lua require("nvim-tree").open_replacing_current_buffer()`
4. Replacing the NvimTree buffer with some other buffer by
   `:e somefile.txt`

The window containing the buffer opened in the first step would be
closed. There would be only a single window with `somefile.txt` on that
tab page.

With this commit, that window is retained and the tab now contains
`firstfile.txt` in the left window and `somefile.txt` in the right
window.
Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests OK. The change is limited in scope to quit_on_open so there are limited chances of side-effects.

Matches documented behaviour:
nvim-tree.actions.open_file.quit_on_open
Closes the explorer when opening a file.
It will also disable preventing a buffer overriding the tree.
Type: boolean, Default: false

@kyazdani42 kyazdani42 merged commit 40e515d into nvim-tree:master Jul 4, 2022
@Gelio
Copy link
Contributor Author

Gelio commented Jul 4, 2022

Thanks for testing and merging this PR! I appreciate it

@Gelio Gelio deleted the fix-unnecessary-closing-windows branch July 4, 2022 12:15
@Gelio Gelio restored the fix-unnecessary-closing-windows branch July 4, 2022 12:15
@Gelio Gelio deleted the fix-unnecessary-closing-windows branch July 4, 2022 12:15
@Gelio Gelio restored the fix-unnecessary-closing-windows branch July 4, 2022 12:15
Almo7aya pushed a commit to Almo7aya/nvim-tree.lua that referenced this pull request Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants