mirror of
https://github.com/neovim/neovim.git
synced 2025-10-14 05:46:12 +00:00
fix(api): do not allow opening float to closing buffer
Problem: no check for nvim_open_win opening a new floating window into a closing buffer, which can lead to crashes. Solution: call check_split_disallowed; opening a new float semantically splits from a window, so the same problems as regular splits apply. Also restore the error if switch_win_noblock in win_set_buf fails (may not be possible to hit this, but win_set_buf can silently succeed there since #31595). As the lock check applies to curbuf (not the target buffer) this may feel a bit restrictive, though this isn't different to how things like ":split" or nvim_open_win with "split = true" works when targeting a different buffer. Only checking the target buffer's lock will cause issues if win_set_buf doesn't end up in the target buffer for whatever reason. Maybe we could consider checking the lock of the buffer after win_set_buf and close the window if it's locked (maybe a bit fiddly, especially as closing a window can fail...), or make the open + switch operation more atomic, like how Vim does for its popup windows..? It also used to be the case that win_set_buf would set an error if autocommands sent us to a different buffer than what was requested, but #31595 appears to have also changed that... I haven't touched that here.
This commit is contained in:
@@ -281,6 +281,9 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(win_config) *config, Err
|
||||
wp->w_config = fconfig;
|
||||
}
|
||||
} else {
|
||||
if (!check_split_disallowed_err(curwin, err)) {
|
||||
goto cleanup; // error already set
|
||||
}
|
||||
wp = win_new_float(NULL, false, fconfig, err);
|
||||
}
|
||||
if (!wp) {
|
||||
|
Reference in New Issue
Block a user