mirror of
https://github.com/neovim/neovim.git
synced 2025-10-04 08:56:29 +00:00
vim-patch:9.1.0116: win_split_ins may not check available room
Problem: win_split_ins has no check for E36 when moving an existing
window
Solution: check for room and fix the issues in f_win_splitmove()
(Sean Dewar)
0fd44a5ad8
Omit WSP_FORCE_ROOM, as it's not needed for Nvim's autocmd window, which is
floating. Shouldn't be difficult to port later if it's used for anything else.
Make win_splitmove continue working for turning floating windows into splits.
Move the logic for "unfloating" a float to win_split_ins; unlike splits, no
changes to the window layout are needed before calling it, as floats take no
room in the window layout and cannot affect the e_noroom check.
Add missing tp_curwin-fixing logic for turning external windows into splits, and
add a test.
NOTE: there are other issues with the way "tabpage independence" is implemented
for external windows; namely, some things assume that tp_curwin is indeed a
window within that tabpage, and as such, functions like tabpage_winnr and
nvim_tabpage_get_win currently don't always work for external windows (with the
latter aborting!)
Use last_status over frame_add_statusline, as Nvim's last_status already does
this for all windows in the current tabpage. Adjust restore_full_snapshot_rec to
handle this.
This "restore everything" approach is changed in a future commit anyway, so only
ensure it's robust enough to just pass tests.
Keep check_split_disallowed's current doc comment, as it's actually a bit more
accurate here. (I should probably PR Vim to use this one)
Allow f_win_splitmove to move a floating "wp" into a split; Nvim supports this.
Continue to disallow it from moving the autocommand window into a split (funnily
enough, the check wasn't reachable before, as moving a float was disallowed),
but now return -1 in that case (win_splitmove also returns FAIL for this, but
handling it in f_win_splitmove avoids us needing to switch windows first).
Cherry-pick Test_window_split_no_room fix from v9.1.0121.
Update nvim_win_set_config to handle win_split_ins failure in later commits.
This commit is contained in:
@@ -659,55 +659,19 @@ void f_win_screenpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
tv_list_append_number(rettv->vval.v_list, wp == NULL ? 0 : wp->w_wincol + 1);
|
||||
}
|
||||
|
||||
/// Move the window wp into a new split of targetwin in a given direction
|
||||
static void win_move_into_split(win_T *wp, win_T *targetwin, int size, int flags)
|
||||
{
|
||||
int height = wp->w_height;
|
||||
win_T *oldwin = curwin;
|
||||
|
||||
if (wp == targetwin || is_aucmd_win(wp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Jump to the target window
|
||||
if (curwin != targetwin) {
|
||||
win_goto(targetwin);
|
||||
}
|
||||
|
||||
// Remove the old window and frame from the tree of frames
|
||||
int dir;
|
||||
winframe_remove(wp, &dir, NULL);
|
||||
win_remove(wp, NULL);
|
||||
last_status(false); // may need to remove last status line
|
||||
win_comp_pos(); // recompute window positions
|
||||
|
||||
// Split a window on the desired side and put the old window there
|
||||
win_split_ins(size, flags, wp, dir);
|
||||
|
||||
// If splitting horizontally, try to preserve height
|
||||
if (size == 0 && !(flags & WSP_VERT)) {
|
||||
win_setheight_win(height, wp);
|
||||
if (p_ea) {
|
||||
win_equal(wp, true, 'v');
|
||||
}
|
||||
}
|
||||
|
||||
if (oldwin != curwin) {
|
||||
win_goto(oldwin);
|
||||
}
|
||||
}
|
||||
|
||||
/// "win_splitmove()" function
|
||||
void f_win_splitmove(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
{
|
||||
win_T *wp = find_win_by_nr_or_id(&argvars[0]);
|
||||
win_T *targetwin = find_win_by_nr_or_id(&argvars[1]);
|
||||
win_T *oldwin = curwin;
|
||||
|
||||
rettv->vval.v_number = -1;
|
||||
|
||||
if (wp == NULL || targetwin == NULL || wp == targetwin
|
||||
|| !win_valid(wp) || !win_valid(targetwin)
|
||||
|| win_float_valid(wp) || win_float_valid(targetwin)) {
|
||||
|| targetwin->w_floating) {
|
||||
emsg(_(e_invalwindow));
|
||||
rettv->vval.v_number = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -732,7 +696,27 @@ void f_win_splitmove(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
size = (int)tv_dict_get_number(d, "size");
|
||||
}
|
||||
|
||||
win_move_into_split(wp, targetwin, size, flags);
|
||||
// Check if we can split the target before we bother switching windows.
|
||||
if (is_aucmd_win(wp) || check_split_disallowed(targetwin) == FAIL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (curwin != targetwin) {
|
||||
win_goto(targetwin);
|
||||
}
|
||||
|
||||
// Autocommands may have sent us elsewhere or closed "wp" or "oldwin".
|
||||
if (curwin == targetwin && win_valid(wp)) {
|
||||
if (win_splitmove(wp, size, flags) == OK) {
|
||||
rettv->vval.v_number = 0;
|
||||
}
|
||||
} else {
|
||||
emsg(_(e_auabort));
|
||||
}
|
||||
|
||||
if (oldwin != curwin && win_valid(oldwin)) {
|
||||
win_goto(oldwin);
|
||||
}
|
||||
}
|
||||
|
||||
/// "win_gettype(nr)" function
|
||||
|
Reference in New Issue
Block a user