-
-
Notifications
You must be signed in to change notification settings - Fork 626
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
Merged
alex-courtis
merged 1 commit into
nvim-tree:master
from
geril2207:fix/floating-remove-opened-file
Nov 5, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,10 @@ local M = { | |
} | ||
|
||
local function close_windows(windows) | ||
if view.View.float.enable and #vim.api.nvim_list_wins() == 1 then | ||
-- Prevent from closing when the win count equals 1 or 2, | ||
-- where the win to remove could be the last opened. | ||
-- For details see #2503. | ||
if view.View.float.enable and #vim.api.nvim_list_wins() < 3 then | ||
return | ||
end | ||
|
||
|
@@ -24,15 +27,15 @@ local function clear_buffer(absolute_path) | |
local bufs = vim.fn.getbufinfo { bufloaded = 1, buflisted = 1 } | ||
for _, buf in pairs(bufs) do | ||
if buf.name == absolute_path then | ||
local tree_winnr = vim.api.nvim_get_current_win() | ||
if buf.hidden == 0 and (#bufs > 1 or view.View.float.enable) then | ||
local winnr = vim.api.nvim_get_current_win() | ||
vim.api.nvim_set_current_win(buf.windows[1]) | ||
vim.cmd ":bn" | ||
if not view.View.float.enable then | ||
vim.api.nvim_set_current_win(winnr) | ||
end | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. found that |
||
vim.api.nvim_set_current_win(tree_winnr) | ||
end | ||
if M.config.actions.remove_file.close_window then | ||
close_windows(buf.windows) | ||
end | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Uh oh!
There was an error while loading. Please reload this page.
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.