Skip to content

Conversation

@nhat-vo
Copy link
Collaborator

@nhat-vo nhat-vo commented Feb 19, 2023

Fixes #759 by cleaning up invalid windows from floating_windows, which is called on events.VIM_RESIZED

@nhat-vo nhat-vo changed the base branch from v2.x to main February 19, 2023 12:43
@nhat-vo nhat-vo requested a review from cseickel February 19, 2023 12:45
Comment on lines 928 to 930
if M.is_window_valid(win.winid) == false then
table.remove(floating_windows, i)
else
Copy link
Contributor

Choose a reason for hiding this comment

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

Removing values from the middle of a table you are iterating on is a bad idea and could produce bugs. In practice we don't usually have more than one window in this collection so you may not have noticed any bugs in testing, but one day this could come back to bite somebody.

It's also generally a good idea to use truthy assertions rather than negative ones where possible, because it is a little easier to read them.

I would suggest:

Suggested change
if M.is_window_valid(win.winid) == false then
table.remove(floating_windows, i)
else
valid_windows = {}
if M.is_window_valid(win.winid) then
table.insert(valid_windows, win)

and then at the end of the loop you can assign:

  floating_windows = valid_windows

to get rid of any invalid windows you may have found along the way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, thank you for the comment. I forgot the fact that table.remove() could cause bugs in a loop.

@cseickel cseickel merged commit 4077fc6 into nvim-neo-tree:main Feb 20, 2023
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.

[Bug] Resizing in tmux pane errors

2 participants