Skip to content
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

Window behavior with vertical split #476

Closed
haoming-li-ling opened this issue Aug 10, 2022 · 6 comments
Closed

Window behavior with vertical split #476

haoming-li-ling opened this issue Aug 10, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@haoming-li-ling
Copy link

If I toggle Neotree in a tab with a vertical split, the following happens:

  1. If I issue the toggle command in the left window, the Neotree window opens in on the left, leaving the right window size unchanged. If I then toggle the Neotree window closed, the cursor goes to the left window.
  2. If I issue the toggle command in the right window, the Neotree window opens in a vsplit on the left, leaving the right window size unchanged. If I then toggle the Neotree window closed, the cursor goes to the left window, instead of the right window (where the toggle command was initially issued).

I think the following behaviors (in fact, default behaviors of nvim-tree.lua) would be better:

  1. Adjust the size of both the windows on the left and on the right when a Neotree window is opened, so they retain their original proportions (windows of equal size remain equal in size with a Neotree window open)
  2. Return the cursor to the window where the toggle command is issued when a Neotree window closes, instead of always to the window on the left

If these behaviors are already available from the configurations, it would be best if someone can show me how.

@cseickel cseickel added the enhancement New feature or request label Aug 10, 2022
@cseickel
Copy link
Contributor

  • Adjust the size of both the windows on the left and on the right when a Neotree window is opened, so they retain their original proportions (windows of equal size remain equal in size with a Neotree window open)

This is the second time someone has requested this and I think it makes sense. I'm sure there are a thousand edge cases though so it will probably be a mess which needs to be optional and off by default. @MunifTanjim is this something that you would want to handle within Nui?

  • Return the cursor to the window where the toggle command is issued when a Neotree window closes, instead of always to the window on the left

What seems the most logical to me is to return the focus to the last visited window. That happens to be the same thing in your scenario, but if the sidebar is open for a long time there can be many window changes in between and it might not make sense to go back to the original window at that point. Going back to the last visited window would always be a predictable behavior.

@MunifTanjim
Copy link
Contributor

MunifTanjim commented Aug 10, 2022

Adjust the size of both the windows on the left and on the right when a Neotree window is opened

It's not just two splits side by side, it can be a complex layout of splits, e.g.

-------------
N |  A | B  |
E |----------
O | C| D |E |
-------------

is this something that you would want to handle within Nui?

I don't think Nui should change sizes of splits not managed by Nui.

This is the second time someone has requested this and I think it makes sense.

I think the better thing would be to fire an event when neo-tree closes, and user can run CTRL-W_= (or any custom function to set the split sizes) when that happens (if they want).

@MunifTanjim
Copy link
Contributor

What seems the most logical to me is to return the focus to the last visited window. That happens to be the same thing in your scenario, but if the sidebar is open for a long time there can be many window changes in between and it might not make sense to go back to the original window at that point. Going back to the last visited window would always be a predictable behavior.

Should only do it if the cursor was on neo-tree window when it was closed. If the cursor was on another window when it closes, do nothing.

@cseickel
Copy link
Contributor

It's not just two splits side by side, it can be a complex layout of splits, e.g.

-------------
N |  A | B  |
E |----------
O | C| D |E |
-------------

Oh yeah, that would be a mess. It would be complicated to figure out the amount that each window should be reduced in that case. There could also be situations where some of the windows should be resized but not all of them. I think this is looking like too buggy a feature to add.

Perhaps a better thing would be for each user to just create their own function to adjust window sizes as they wish.

I think the better thing would be to fire an event when neo-tree closes, and user can run CTRL-W_= (or any custom function to set the split sizes) when that happens (if they want).

This might be a better solution... I can add all of these:

  • before_window_open
  • after_window_open
  • before_window_close
  • after_window_close

That should be enough to handle this situation, and open up the possibilities of other customizations. A simple solution using the above events would be to just <C-w>= in after_window_open and after_window_close, and I can add that as a recipe in the wiki.

@haoming-li-ling
Copy link
Author

What seems the most logical to me is to return the focus to the last visited window. That happens to be the same thing in your scenario, but if the sidebar is open for a long time there can be many window changes in between and it might not make sense to go back to the original window at that point. Going back to the last visited window would always be a predictable behavior.

Should only do it if the cursor was on neo-tree window when it was closed. If the cursor was on another window when it closes, do nothing.

That should be enough to handle this situation, and open up the possibilities of other customizations. A simple solution using the above events would be to just <C-w>= in after_window_open and after_window_close, and I can add that as a recipe in the wiki.

These look like great solutions! Looking forward.

@cseickel
Copy link
Contributor

This is complete, and here is the recipe in the Wiki: https://github.com/nvim-neo-tree/neo-tree.nvim/wiki/Recipes#equalize-window-sizes-on-neo-tree-open-and-close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants