1
mirror of https://github.com/neovim/neovim.git synced 2024-12-27 14:21:31 -07:00

fix(column): fix wrong cursor with 'statuscolumn' and cpo+=n ()

This commit is contained in:
zeertzjq 2023-07-06 11:07:23 +08:00 committed by GitHub
parent a0c9c04f00
commit 25e62697c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 5 deletions
src/nvim
test/functional/ui

View File

@ -748,7 +748,7 @@ static void get_statuscol_display_info(statuscol_T *stcp, winlinevars_T *wlv)
// Skip over empty highlight sections
} while (wlv->n_extra == 0 && stcp->textp < stcp->text_end);
if (wlv->n_extra > 0) {
static char transbuf[MAX_NUMBERWIDTH * MB_MAXBYTES + 1];
static char transbuf[(MAX_NUMBERWIDTH + 9 + 9 * 2) * MB_MAXBYTES + 1];
wlv->n_extra = (int)transstr_buf(wlv->p_extra, wlv->n_extra, transbuf, sizeof transbuf, true);
wlv->p_extra = transbuf;
}

View File

@ -775,9 +775,9 @@ void validate_cursor_col(void)
// fold column and sign column (these don't move when scrolling horizontally).
int win_col_off(win_T *wp)
{
return ((wp->w_p_nu || wp->w_p_rnu || (*wp->w_p_stc != NUL)) ?
return ((wp->w_p_nu || wp->w_p_rnu || *wp->w_p_stc != NUL) ?
(number_width(wp) + (*wp->w_p_stc == NUL)) : 0)
+ (cmdwin_type == 0 || wp != curwin ? 0 : 1)
+ ((cmdwin_type == 0 || wp != curwin) ? 0 : 1)
+ win_fdccol_count(wp)
+ (win_signcol_count(wp) * win_signcol_width(wp));
}
@ -792,8 +792,9 @@ int curwin_col_off(void)
// is in 'cpoptions'.
int win_col_off2(win_T *wp)
{
if ((wp->w_p_nu || wp->w_p_rnu) && vim_strchr(p_cpo, CPO_NUMCOL) != NULL) {
return number_width(wp) + 1;
if ((wp->w_p_nu || wp->w_p_rnu || *wp->w_p_stc != NUL)
&& vim_strchr(p_cpo, CPO_NUMCOL) != NULL) {
return number_width(wp) + (*wp->w_p_stc == NUL);
}
return 0;
}

View File

@ -356,6 +356,64 @@ describe('statuscolumn', function()
{2: }{1: }{2: }{1: }aaaaaaaaaaaaaaaaaaaa |
|
]])
-- Also test fold and sign column when 'cpoptions' includes "n"
command('set cpoptions+=n')
feed('Hgjg0')
screen:expect([[
{2: }{4: 0}{1:>>}{2: }{4: }{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{2: }{5:^aaaaaaaaaaaaaaaaaaaa }|
{2: }{1: 3}{0:>!}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa |
{2: }{1: 2>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa |
{2: }{1: 1}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa |
{2:+}{1: 4}{2: }{1: }{3:+-- 1 line: aaaaaaaaaaaaaaaaa}|
{2: }{1: 1}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa |
{2: }{1: 2}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa |
|
]])
command('set breakindent')
feed('J2gjg0')
screen:expect([[
{2: }{4: 0}{1:>>}{2: }{4: }{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{2: } {5:aaaaaaaaaaaaaaaaaaaa aaaaaaaaa}|
{2: } {5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{2: } {5:^aaaaaaaaaaa }|
{2: }{1: 1>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: } aaaaaaaaaaaaaaaaaaaa |
{2: }{1: 2}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: } aaaaaaaaaaaaaaaaaaaa |
{2:+}{1: 3}{2: }{1: }{3:+-- 1 line: aaaaaaaaaaaaaaaaa}|
{2: }{1: 4}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: } aaaaaaaaaaaaaaaaaaaa |
{2: }{1: 5}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: } aaaaaaaaaaaaaaaaaaaa |
|
]])
command('set nobreakindent')
feed('$g0')
screen:expect([[
{2: }{4: 0}{1:>>}{2: }{4: }{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{2: }{5:aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaa}|
{2: }{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{2: }{5:^aaa }|
{2: }{1: 1>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa |
{2: }{1: 2}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa |
{2:+}{1: 3}{2: }{1: }{3:+-- 1 line: aaaaaaaaaaaaaaaaa}|
{2: }{1: 4}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa |
{2: }{1: 5}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa |
|
]])
command('silent undo')
feed('8gg')
command('set cpoptions-=n')
-- Status column is re-evaluated for virt_lines, buffer line, and wrapped line
exec_lua([[
vim.api.nvim_buf_set_extmark(0, ns, 5, 0, {