]> granicus.if.org Git - vim/commitdiff
patch 8.1.1623: display wrong with signs in narrow number column v8.1.1623
authorBram Moolenaar <Bram@vim.org>
Thu, 4 Jul 2019 09:59:28 +0000 (11:59 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 4 Jul 2019 09:59:28 +0000 (11:59 +0200)
Problem:    Display wrong with signs in narrow number column.
Solution:   Increase the numbercolumn width if needed. (Yegappan Lakshmanan,
            closes #4606)

src/option.c
src/screen.c
src/sign.c
src/testdir/test_signs.vim
src/version.c

index cd50e8d622b188ab02df4a16e3a51b4caa97b09f..4856a598d6877ed691d71b588a304fe06c4d099b 100644 (file)
@@ -7454,11 +7454,17 @@ did_set_string_option(
 #endif /* FEAT_INS_EXPAND */
 
 #ifdef FEAT_SIGNS
-    /* 'signcolumn' */
+    // 'signcolumn'
     else if (varp == &curwin->w_p_scl)
     {
        if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
            errmsg = e_invarg;
+       // When changing the 'signcolumn' to or from 'number', recompute the
+       // width of the number column if 'number' or 'relativenumber' is set.
+       if (((*oldval == 'n' && *(oldval + 1) == 'u')
+               || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u'))
+               && (curwin->w_p_nu || curwin->w_p_rnu))
+           curwin->w_nrwidth_line_count = 0;
     }
 #endif
 
index d39fca2637a79ee32aa760776f4b42571d138b03..b810065abf788c7e8a0fbdf9ef7f103ceb1c87bb 100644 (file)
@@ -11333,6 +11333,14 @@ number_width(win_T *wp)
     if (n < wp->w_p_nuw - 1)
        n = wp->w_p_nuw - 1;
 
+# ifdef FEAT_SIGNS
+    // If 'signcolumn' is set to 'number' and there is a sign to display, then
+    // the minimal width for the number column is 2.
+    if (n < 2 && (wp->w_buffer->b_signlist != NULL)
+           && (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u'))
+       n = 2;
+# endif
+
     wp->w_nrwidth_width = n;
     wp->w_nuw_cached = wp->w_p_nuw;
     return n;
index 7ea40abf1fca1cef7d7f00a1d88cae030a070979..a67f3ec8cf8fb23928e0ffdc19b61fff0a6d1918 100644 (file)
@@ -1008,6 +1008,20 @@ sign_list_by_name(char_u *name)
        semsg(_("E155: Unknown sign: %s"), name);
 }
 
+    static void
+may_force_numberwidth_recompute(buf_T *buf, int unplace)
+{
+    tabpage_T  *tp;
+    win_T              *wp;
+
+    FOR_ALL_TAB_WINDOWS(tp, wp)
+       if (wp->w_buffer == buf
+               && (wp->w_p_nu || wp->w_p_rnu)
+               && (unplace || wp->w_nrwidth_width < 2)
+               && (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u'))
+           wp->w_nrwidth_line_count = 0;
+}
+
 /*
  * Place a sign at the specified file location or update a sign.
  */
@@ -1045,7 +1059,13 @@ sign_place(
        // ":sign place {id} file={fname}": change sign type
        lnum = buf_change_sign_type(buf, *sign_id, sign_group, sp->sn_typenr);
     if (lnum > 0)
+    {
        redraw_buf_line_later(buf, lnum);
+
+       // When displaying signs in the 'number' column, if the width of the
+       // number column is less than 2, then force recomputing the width.
+       may_force_numberwidth_recompute(buf, FALSE);
+    }
     else
     {
        semsg(_("E885: Not possible to change sign %s"), sign_name);
@@ -1080,6 +1100,12 @@ sign_unplace(int sign_id, char_u *sign_group, buf_T *buf, linenr_T atlnum)
            return FAIL;
     }
 
+    // When all the signs in a buffer are removed, force recomputing the
+    // number column width (if enabled) in all the windows displaying the
+    // buffer if 'signcolumn' is set to 'number' in that window.
+    if (buf->b_signlist == NULL)
+       may_force_numberwidth_recompute(buf, TRUE);
+
     return OK;
 }
 
index c979804a80b22114ad8226741c1733deee1acdce..898acbc38e610ef5277be393e4b1a7002f1901ff 100644 (file)
@@ -1788,6 +1788,56 @@ func Test_sign_numcol()
   redraw!
   call assert_equal("=>  1 01234", s:ScreenLine(1, 1, 11))
 
+  " Test displaying signs in the number column with width 1
+  call sign_unplace('*')
+  call append(1, "abcde")
+  call append(2, "01234")
+  " Enable number column with width 1
+  set number numberwidth=1 signcolumn=auto
+  redraw!
+  call assert_equal("3 01234", s:ScreenLine(3, 1, 7))
+  " Place a sign and make sure number column width remains the same
+  sign place 20 line=2 name=sign1
+  redraw!
+  call assert_equal("=>2 abcde", s:ScreenLine(2, 1, 9))
+  call assert_equal("  3 01234", s:ScreenLine(3, 1, 9))
+  " Set 'signcolumn' to 'number', make sure the number column width increases
+  set signcolumn=number
+  redraw!
+  call assert_equal("=> abcde", s:ScreenLine(2, 1, 8))
+  call assert_equal(" 3 01234", s:ScreenLine(3, 1, 8))
+  " Set 'signcolumn' to 'auto', make sure the number column width is 1.
+  set signcolumn=auto
+  redraw!
+  call assert_equal("=>2 abcde", s:ScreenLine(2, 1, 9))
+  call assert_equal("  3 01234", s:ScreenLine(3, 1, 9))
+  " Set 'signcolumn' to 'number', make sure the number column width is 2.
+  set signcolumn=number
+  redraw!
+  call assert_equal("=> abcde", s:ScreenLine(2, 1, 8))
+  call assert_equal(" 3 01234", s:ScreenLine(3, 1, 8))
+  " Disable 'number' column
+  set nonumber
+  redraw!
+  call assert_equal("=>abcde", s:ScreenLine(2, 1, 7))
+  call assert_equal("  01234", s:ScreenLine(3, 1, 7))
+  " Enable 'number' column
+  set number
+  redraw!
+  call assert_equal("=> abcde", s:ScreenLine(2, 1, 8))
+  call assert_equal(" 3 01234", s:ScreenLine(3, 1, 8))
+  " Remove the sign and make sure the width of the number column is 1.
+  call sign_unplace('', {'id' : 20})
+  redraw!
+  call assert_equal("3 01234", s:ScreenLine(3, 1, 7))
+  " When the first sign is placed with 'signcolumn' set to number, verify that
+  " the number column width increases
+  sign place 30 line=1 name=sign1
+  redraw!
+  call assert_equal("=> 01234", s:ScreenLine(1, 1, 8))
+  call assert_equal(" 2 abcde", s:ScreenLine(2, 1, 8))
+
+  sign unplace * group=*
   sign undefine sign1
   set signcolumn&
   set number&
index efad64cad03e6693e08803092cbffc55ad503531..8e2399f43093e7785cf448f54f0bb236d25e2a72 100644 (file)
@@ -777,6 +777,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1623,
 /**/
     1622,
 /**/