-
-
Notifications
You must be signed in to change notification settings - Fork 625
fix: error when deleting opened file from floating window #2503
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
fix: error when deleting opened file from floating window #2503
Conversation
a322a1d
to
4e3f878
Compare
end | ||
vim.api.nvim_buf_delete(buf.bufnr, { force = true }) | ||
if not view.View.float.quit_on_focus_loss then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
found that vim.api.nvim_buf_delete
does not delete the buffer if focus on float window, so firstly delete buffer then return focus.
4e3f878
to
0c54fa2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work, tested OK:
not float.enable
- remove only tree open
- remove open
- remove not open
- open in multiple windows
not float.enable and not float.quit_on_focus_loss
- remove only tree open
- remove open
- remove not open
- open in multiple windows
float.enable and float.quit_on_focus_loss
- remove only tree open
- remove open
- remove not open
- open in multiple windows - the window changes to
#
; that's fine
float.enable and not float.quit_on_focus_loss
- remove only tree open
- remove open
- remove not open
- open in multiple windows
Please:
- add a comment RE magic number
@@ -9,7 +9,7 @@ local M = { | |||
} | |||
|
|||
local function close_windows(windows) | |||
if view.View.float.enable and #vim.api.nvim_list_wins() == 1 then | |||
if view.View.float.enable and #vim.api.nvim_list_wins() < 3 then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please leave a comment explaining the magic number 3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial problem was in case where list of wins is 2 (float tree, and opened buffer), so when trying to delete opened buffer window, vim throws an error cannot close last window. Is there a case where list can be 1? If it possible we save previous condition and add if not 2
(< 3
just looks more compact) which prevents from closing the last window.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally we could check if the window count is 2, and there is no floating tree, in which case we could close the window. But even with quit_on_focus_loss
, list_wins
length would be 2 including floating tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Safety first, thank you.
0c54fa2
to
194cc29
Compare
194cc29
to
1910367
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for your contribution!
@@ -9,7 +9,7 @@ local M = { | |||
} | |||
|
|||
local function close_windows(windows) | |||
if view.View.float.enable and #vim.api.nvim_list_wins() == 1 then | |||
if view.View.float.enable and #vim.api.nvim_list_wins() < 3 then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Safety first, thank you.
#2480