annoying window behavior with noequalalways and splitright

17 views
Skip to first unread message

Mark Waggoner

unread,
Apr 14, 2020, 1:23:01 PM4/14/20
to vim_dev
If you have splitright and noequalalways set, when you split a window (normal horizontal split, not vertical split), the split will appear above the current window.
When you close the split window, the space is restored to the window ABOVE, not back to the window below.

I can see that this is intentionally done in window.c:
/*
 * Return a pointer to the frame that will receive the empty screen space that
 * is left over after "win" is closed.
 *
 * If 'splitbelow' or 'splitright' is set, the space goes above or to the left
 * by default.  Otherwise, the free space goes below or to the right.  The
 * result is that opening a window and then immediately closing it will
 * preserve the initial window layout.  The 'wfh' and 'wfw' settings are
 * respected when possible.
 */
    static frame_T *
win_altframe(

Is there some way to have this be a little more intelligent about where the window space is restored?

Mark Waggoner



Mark Waggoner

unread,
Apr 14, 2020, 6:29:50 PM4/14/20
to vim_dev
This seems to work better:

diff --git i/src/window.c w/src/window.c
index 7efe7b164..e28955d1b 100644
--- i/src/window.c
+++ w/src/window.c
@@ -2967,10 +2967,18 @@ win_altframe(
     if (frp->fr_next == NULL)
        return frp->fr_prev;
 
+    // By default the next window will get the space that was abandoned by this window
     target_fr = frp->fr_next;
     other_fr  = frp->fr_prev;
-    if (p_spr || p_sb)
-    {
+
+    // If this is part of a column of windows, and splitbelow is true then the previous will get the space
+    if (frp->fr_parent != NULL && frp->fr_parent->fr_layout == FR_COL && p_sb) {
+       target_fr = frp->fr_prev;
+       other_fr  = frp->fr_next;
+    }
+
+    // If this is part of a row of windows, and splitright is true then the previous will get the space
+    if (frp->fr_parent != NULL && frp->fr_parent->fr_layout == FR_ROW && p_spr) {
        target_fr = frp->fr_prev;
        other_fr  = frp->fr_next;

Mark Waggoner

unread,
Apr 14, 2020, 8:52:47 PM4/14/20
to vim_dev
Here's a test:

diff --git i/src/testdir/test_winbuf_close.vim w/src/testdir/test_winbuf_close.vim
index 7f5b80e8d..f32735e45 100644
--- i/src/testdir/test_winbuf_close.vim
+++ w/src/testdir/test_winbuf_close.vim
@@ -194,3 +194,23 @@ func Test_tabwin_close()
   call assert_true(v:true)
   %bwipe!
 endfunc
+
+
+" Test if closing a split window (above/below) restores space to the window
+" below when noequalalways and splitright are set
+"
+func Test_window_close_splitright_noequalalways()
+    set noequalalways
+    set splitright
+    new
+    let l:w1 = win_getid()
+    new
+    let l:w2 = win_getid()
+    execute "normal \<c-w>b"
+    let l:h = winheight(0)
+    let l:w = win_getid()
+    new 
+    q
+    call assert_equal(l:h,winheight(0),"Window height does not match height before opening and closing another window")
+    call assert_equal(l:w,win_getid(),"Did not return to original window after opening and closing a window")
+endfunc

Bram Moolenaar

unread,
Apr 15, 2020, 2:06:24 PM4/15/20
to vim...@googlegroups.com, Mark Waggoner

Mark Waggoner wrote:

> Here's a test:

Thanks! Always nice when someone fixes the problem they reported
themselves :-).

--
"The future's already arrived - it's just not evenly distributed yet."
-- William Gibson

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages