]> granicus.if.org Git - vim/commitdiff
patch 8.0.1790: 'winfixwidth' is not always respected by :close v8.0.1790
authorBram Moolenaar <Bram@vim.org>
Fri, 4 May 2018 18:15:38 +0000 (20:15 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 4 May 2018 18:15:38 +0000 (20:15 +0200)
Problem:    'winfixwidth' is not always respected by :close.
Solution:   Prefer a frame without 'winfixwidth' or 'winfixheight'. (Jason
            Franklin)

src/testdir/test_winbuf_close.vim
src/version.c
src/window.c

index ed64dd79b73086505aec9a959e9a3cdc46e5e845..e4618610cd790e300c64a44db4ca16394cdcf35a 100644 (file)
@@ -122,3 +122,39 @@ func Test_winbuf_close()
   call delete('Xtest2')
   call delete('Xtest3')
 endfunc
+
+" Test that ":close" will respect 'winfixheight' when possible.
+func Test_winfixheight_on_close()
+  set nosplitbelow nosplitright
+
+  split | split | vsplit
+
+  $wincmd w
+  setlocal winfixheight
+  let l:height = winheight(0)
+
+  3close
+
+  call assert_equal(l:height, winheight(0))
+
+  %bwipeout!
+  setlocal nowinfixheight splitbelow& splitright&
+endfunc
+
+" Test that ":close" will respect 'winfixwidth' when possible.
+func Test_winfixwidth_on_close()
+  set nosplitbelow nosplitright
+
+  vsplit | vsplit | split
+
+  $wincmd w
+  setlocal winfixwidth
+  let l:width = winwidth(0)
+
+  3close
+
+  call assert_equal(l:width, winwidth(0))
+
+  %bwipeout!
+  setlocal nowinfixwidth splitbelow& splitright&
+endfunction
index 9d00e46c8a32d1d51959a783efbef660a1c54774..467b14e4f88bf4425586e6738ded5c07448bf6ce 100644 (file)
@@ -761,6 +761,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1790,
 /**/
     1789,
 /**/
index 333663ba36b1e8bac0ef570951f143186ab5af28..d3ec4cd025ca3d1220d1b52362c546658f55ec61 100644 (file)
@@ -2740,12 +2740,14 @@ winframe_remove(
 }
 
 /*
- * Find out which frame is going to get the freed up space when "win" is
- * closed.
- * if 'splitbelow'/'splitleft' the space goes to the window above/left.
- * if 'nosplitbelow'/'nosplitleft' the space goes to the window below/right.
- * This makes opening a window and closing it immediately keep the same window
- * layout.
+ * 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(
@@ -2753,20 +2755,40 @@ win_altframe(
     tabpage_T  *tp)            /* tab page "win" is in, NULL for current */
 {
     frame_T    *frp;
-    int                b;
+    frame_T    *other_fr, *target_fr;
 
     if (tp == NULL ? ONE_WINDOW : tp->tp_firstwin == tp->tp_lastwin)
-       /* Last window in this tab page, will go to next tab page. */
        return alt_tabpage()->tp_curwin->w_frame;
 
     frp = win->w_frame;
+
+    if (frp->fr_prev == NULL)
+       return frp->fr_next;
+    if (frp->fr_next == NULL)
+       return frp->fr_prev;
+
+    target_fr = frp->fr_next;
+    other_fr  = frp->fr_prev;
+    if (p_spr || p_sb)
+    {
+       target_fr = frp->fr_prev;
+       other_fr  = frp->fr_next;
+    }
+
+    /* If 'wfh' or 'wfw' is set for the target and not for the alternate
+     * window, reverse the selection. */
     if (frp->fr_parent != NULL && frp->fr_parent->fr_layout == FR_ROW)
-       b = p_spr;
+    {
+       if (frame_fixed_width(target_fr) && !frame_fixed_width(other_fr))
+           target_fr = other_fr;
+    }
     else
-       b = p_sb;
-    if ((!b && frp->fr_next != NULL) || frp->fr_prev == NULL)
-       return frp->fr_next;
-    return frp->fr_prev;
+    {
+       if (frame_fixed_height(target_fr) && !frame_fixed_height(other_fr))
+           target_fr = other_fr;
+    }
+
+    return target_fr;
 }
 
 /*