echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
4.84k stars 183 forks source link

File window of mini.files crash when using mini.bracketed or mini.bufremove commands #1173

Closed Gael-Lopes-Da-Silva closed 2 weeks ago

Gael-Lopes-Da-Silva commented 2 weeks ago

Contributing guidelines

Module(s)

mini.files mini.bracketed mini.bufremove

Description

When the file window of mini.files is open and I use mini.bracketed to switch buffer or use mini.bufremove to close a buffer with the windows still open, it crash the window and throw an error and let it open as an artifact.

image

Neovim version

0.10.1

Steps to reproduce

  1. nvim -nu minimal.lua
  2. Open mini.files with :lua MiniFiles.open()
  3. Do [b, ]b, :lua MiniBufremove.delete() or :lua MiniBufremove.unshow() (either one of those 4)

Expected behavior

Either do the expected behavior of the command or keybind or do nothing

Actual behavior

Crash the floating window and let an artifact on the screen

echasnovski commented 2 weeks ago

Thanks for the issue!

I can reproduce. not sure if this is a reasonable use case to account for though: neither deleting a buffer nor switching to another one makes sense inside a file explorer. And all the windows after the error can be closed with <C-w>o (and the fact that they don't close automatically may the real issue here). I'll think about it.

Gael-Lopes-Da-Silva commented 2 weeks ago

Thanks for the issue!

I can reproduce. not sure if this is a reasonable use case to account for though: neither deleting a buffer nor switching to another one makes sense inside a file explorer. And all the windows after the error can be closed with <C-w>o (and the fact that they don't close automatically may the real issue here). I'll think about it.

I'm happy to help.

For me, the problem does not lay in the use case (because like you said, it does not make sens to switch buffer or close buffer in the file explorer) but in the fact that opening the file explorer, switching buffers or closing buffers are common things to do. For example, I hit the switch buffer or close buffer key without closing the file explorer, because I made a mistake or I typed to quickly. When that happens, even if you can close the window with <C-w>o, you can't reopen the file explorer afterwards. It requires to restart neovim and it's a bit of a workflow breaker.

As a workaround, I manually modified the keybindings to add the following in my config files:

if not require("mini.files").close() then
    -- The command
end

I'm pretty sure that it's not the best way to do that. It may be better to check if a file explorer is open and if its false do the command, else do nothing than to close it if it's true, but I don't know how to do that as of now (is there a way by checking the MiniFiles events ? or a function ?).

echasnovski commented 2 weeks ago

When that happens, even if you can close the window with <C-w>o, you can't reopen the file explorer afterwards. It requires to restart neovim and it's a bit of a workflow breaker.

I briefly checked earlier and I could open it up again. After rechecking again, I can definitely reproduce it not opening again, but not on the first try and under some not trivial steps.

I agree, having to account for opened explorer in mappings is not ideal and should not be required. I'll take a look (at least there is 'winfixbuf' option in Neovim>=0.10 which seems to make it work by showing error but explorer is still valid).

It may be better to check if a file explorer is open and if its false do the command, else do nothing than to close it if it's true, but I don't know how to do that as of now (is there a way by checking the MiniFiles events ? or a function ?).

Although shouldn't be needed for this case, I plan to add such function soon because there is a #1162 that could benefit from it.

echasnovski commented 2 weeks ago

This should now be resolved on latest main, but only for Neovim>=0.10. Trying to switch buffers will show an error (which is expected because 'mini.files' windows are expected to show only dedicated buffers) but explorer will be fully usable afterwards. The reason it is resolved only on Neovim>=0.10 is because it introduced the 'winfixbuf' option which allows permanently "pair" window and buffer.

echasnovski commented 1 week ago

It may be better to check if a file explorer is open and if its false do the command, else do nothing than to close it if it's true, but I don't know how to do that as of now (is there a way by checking the MiniFiles events ? or a function ?).

Although shouldn't be needed for this case, I plan to add such function soon because there is a #1162 that could benefit from it.

There is now a get_explorer_state() function. It can be used to check if there is an active explorer via MiniFiles.get_explorer_state() ~= nil.