mirror of
https://github.com/neovim/neovim.git
synced 2025-10-16 23:06:14 +00:00
feat(api): allow open_win/win_set_buf in the cmdwin in some cases
Problem: As discussed on Matrix, there was some interest in having `nvim_open_win` again be able to open floats in the cmdwin (e.g: displaying a hover doc related to what's in the cmdwin). After #23228, this was disallowed. Solution: Allow `nvim_open_win` in the cmdwin as long as `!enter` and `buffer != curbuf` (the former can cause all sorts of issues, and the latter can crash Nvim after closing cmdwin). Also allow `nvim_win_set_buf` in a similar fashion. Note that we're not *entirely* sure if this is 100% safe (cmdwin is a global-state-using-main-loop-calling beast), but this seems to work OK..? Also: - Check the buffer argument of `nvim_open_win` earlier, and abort if it's invalid (it used to still open a window in this case). - Untranslate `e_cmdwin` errors in the API (other errors in the API are not translated: although not detailed in the API contract yet, errors are supposed to be stable).
This commit is contained in:
@@ -698,15 +698,9 @@ static void cmd_with_count(char *cmd, char *bufp, size_t bufsize, int64_t Prenum
|
||||
}
|
||||
}
|
||||
|
||||
void win_set_buf(Window window, Buffer buffer, bool noautocmd, Error *err)
|
||||
void win_set_buf(win_T *win, buf_T *buf, bool noautocmd, Error *err)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
win_T *win = find_window_by_handle(window, err);
|
||||
buf_T *buf = find_buffer_by_handle(buffer, err);
|
||||
|
||||
if (!win || !buf) {
|
||||
return;
|
||||
}
|
||||
|
||||
tabpage_T *tab = win_find_tabpage(win);
|
||||
|
||||
// no redrawing and don't set the window title
|
||||
@@ -720,7 +714,7 @@ void win_set_buf(Window window, Buffer buffer, bool noautocmd, Error *err)
|
||||
api_set_error(err,
|
||||
kErrorTypeException,
|
||||
"Failed to switch to window %d",
|
||||
window);
|
||||
win->handle);
|
||||
}
|
||||
|
||||
try_start();
|
||||
@@ -729,7 +723,7 @@ void win_set_buf(Window window, Buffer buffer, bool noautocmd, Error *err)
|
||||
api_set_error(err,
|
||||
kErrorTypeException,
|
||||
"Failed to set buffer %d",
|
||||
buffer);
|
||||
buf->handle);
|
||||
}
|
||||
|
||||
// If window is not current, state logic will not validate its cursor.
|
||||
|
Reference in New Issue
Block a user