-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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(api): various window-related function fixes #27330
Conversation
This looks great! I'm working on fixes for some of the split behavior btw, unless you were planning on doing that. |
Feel free to work on that! I only plan to address some random things I find here. |
Sounds good! |
da02c6d
to
e0dd9b5
Compare
nvim_win_set_config
splitting fixesnvim_win_set_config
, nvim_open_win
fixes
71d3690
to
de1f6ad
Compare
This comment was marked as resolved.
This comment was marked as resolved.
c7f250e
to
757d1cb
Compare
nvim_win_set_config
, nvim_open_win
fixesProblem: win_enter autocommands can close new_curwin, crashing if it was the last window in its tabpage after removing win, or can close parent, crashing when attempting to split it later. Solution: remove win first, check that parent is valid after win_enter. NOTE: This isn't actually quite right, as this means win is not in the window list or even has a frame when triggering enter autocommands (so it's not considered valid in the tabpage). This is addressed in later commits.
Problem: win_set_config should have the observable effect of moving an existing window to another place, but instead fires autocommands as if a new window was created and entered (and does not fire autocommands reflecting a "return" to the original window). Solution: do not fire win_enter-related autocommands when splitting the window, but continue to fire them when entering the window that fills the new space when moving a window to a different tabpage, as the new curwin changes. Also, remove "++once" from the WinEnter autocmd in the other test, as omitting it also crashed Nvim before this fix.
757d1cb
to
a8c9394
Compare
About time I open this for reviews before the scope increases more 🙈. There are a few other things I discovered that I haven't addressed here:
Also, I assume |
…noautocmd Problem: BufWinEnter is not fired when not entering a new window, even when a different buffer is specified and buffer-related autocommands are unblocked (!noautocmd). Solution: fire it in the context of the new window and buffer. Do not do it if the buffer is unchanged, like :{s}buffer. Be wary of autocommands! For example, it's possible for nvim_win_set_config to be used in an autocommand to move a window to a different tabpage (in contrast, things like wincmd T actually create a *new* window, so it may not have been possible before, meaning other parts of Nvim could assume windows can't do this... I'd be especially cautious of logic that restores curwin and curtab without checking if curwin is still valid in curtab, if any such logic exists). Also, bail early from win_set_buf if setting the temp curwin fails; this shouldn't be possible, as the callers check that wp is valid, but in case that's not true, win_set_buf will no longer continue setting a buffer for the wrong window. Note that pum_create_float_preview also uses win_set_buf, but from a glance, doesn't look like it properly checks for autocmds screwing things up (win_enter, nvim_create_buf...). I haven't addressed that here. Also adds some test coverage for nvim_open_win autocommands. Closes neovim#27121.
Problem: nvim_win_set_config does not update statuslines after removing a split. Solution: call last_status. Didn't realize this was missing in the original nvim_win_set_config for splits PR. As it can only be done for the current tabpage, do it if win_tp == curtab; enter_tabpage will eventually call last_status anyway when the user enters another tabpage.
Its corresponding test in Vim is in test_popupwin.win, so having it in the middle of test_window_cmd.vim is strange, and it is now covered by tests in ui/float_spec.lua anyway.
I also pushed some follow-up commits. That pending test I added is a bit tricky to fix (as it will likely require changing |
88d2c60
to
7dc4cd6
Compare
Problem: :close may cause Nvim to quit if an autocommand triggered when closing the buffer closes all other non-floating windows and there are floating windows. Solution: Correct the check for the only non-floating window.
7dc4cd6
to
33dfb5a
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Problem: nvim_win_set_config does not update the tp_curwin of win's original tabpage when moving it to another. Solution: update it if win was the tp_curwin. Add a test.
Problem: Crash on exit with EXITFREE and using win_execute(). Solution: Also save and restore tp_topframe. (issue vim/vim#9374) vim/vim@dab17a0 Couldn't repro the crash in the test, but I only care about this patch so switch_win sets topframe properly for win_split_ins in nvim_open_win and nvim_win_set_config. Add a test using nvim_win_call and :wincmd, as I couldn't repro the issue via nvim_open_win or nvim_win_set_config (though it's clear they're affected by this patch). That said, at that point, could just use {un}use_tabpage inside switch_win instead, which also updates tp_curwin (though maybe continue to not set it in restore_win). That would also fix possible inconsistent behaviour such as: :call win_execute(w, "let curwin_nr1 = tabpagewinnr(1)") :let curwin_nr2 = tabpagewinnr(1) Where it's possible for curwin_nr1 != curwin_nr2 if these commands are run from the 1st tabpage, but window "w" is in the 2nd (as the 1st tabpage's tp_curwin may still be invalid). I'll probably PR a fix for that later in Vim. Co-authored-by: Bram Moolenaar <[email protected]>
60e9785
to
069bdb4
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
069bdb4
to
60e9785
Compare
This comment was marked as resolved.
This comment was marked as resolved.
60e9785
to
c3d22d3
Compare
Okie dokie, I've pushed the commits on top of that state (and amended the Here's the diff of that. |
Ok, I'm totally over this PR at this point. 😆 Once checks are green, I'm happy to merge immediately if that sounds good. 👍 |
Awesome! Not sure I could have provided any helpful reviews here as a lot of this is beyond my Vim knowledge (for now...) but this PR has been very informative to read through. |
Now time to hope I didn't break anything 😇 |
Follows up on some issues in #25550 and (a bunch of) other things
Also includes Vim patches to issues I found while working on things: 8.2.3862, 9.1.{0116,0118,0119,0121,0128,0130} (and 9.1.0117 as a partial patch).