diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/option.c | 7 | ||||
-rw-r--r-- | src/nvim/screen.c | 12 | ||||
-rw-r--r-- | src/nvim/sign.c | 22 | ||||
-rw-r--r-- | src/nvim/testdir/test_signs.vim | 50 |
4 files changed, 89 insertions, 2 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index 4157d28894..97f31b4754 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3183,6 +3183,13 @@ ambw_end: 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; + } } else if (varp == &curwin->w_p_fdc || varp == &curwin->w_allbuf_opt.wo_fdc) { // 'foldcolumn' if (check_opt_strings(*varp, p_fdc_values, false) != OK) { diff --git a/src/nvim/screen.c b/src/nvim/screen.c index e9df68f657..92a34dfc42 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -7400,9 +7400,17 @@ int number_width(win_T *wp) ++n; } while (lnum > 0); - /* 'numberwidth' gives the minimal width plus one */ - if (n < wp->w_p_nuw - 1) + // 'numberwidth' gives the minimal width plus one + if (n < wp->w_p_nuw - 1) { n = wp->w_p_nuw - 1; + } + + // 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; + } wp->w_nrwidth_width = n; return n; diff --git a/src/nvim/sign.c b/src/nvim/sign.c index ab5d04d39b..ffe51287c5 100644 --- a/src/nvim/sign.c +++ b/src/nvim/sign.c @@ -881,6 +881,17 @@ int sign_undefine_by_name(const char_u *name) return OK; } +static void may_force_numberwidth_recompute(buf_T *buf, int unplace) +{ + 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; + } +} + /// List the signs matching 'name' static void sign_list_by_name(char_u *name) { @@ -935,6 +946,10 @@ int sign_place( } 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 { EMSG2(_("E885: Not possible to change sign %s"), sign_name); return FAIL; @@ -964,6 +979,13 @@ int sign_unplace(int sign_id, char_u *sign_group, buf_T *buf, linenr_T atlnum) redraw_buf_line_later(buf, lnum); } + // 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; } diff --git a/src/nvim/testdir/test_signs.vim b/src/nvim/testdir/test_signs.vim index f89095ec5d..9d1146453a 100644 --- a/src/nvim/testdir/test_signs.vim +++ b/src/nvim/testdir/test_signs.vim @@ -1796,6 +1796,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& |