refactor(plines): use a struct for chartabsize state

This is a refactor extracted from vim-patch 9.0.0067: cannot show virtual text

The logic for inline virtual text is going to be different in nvim than
text property based text in vim, but this refactor is still useful,
as calculation of displayed linesize is going to be stateful in a
similar way.
This commit is contained in:
bfredl
2022-08-27 11:28:11 +02:00
parent 7a9b593796
commit ea4e9c71cc
16 changed files with 354 additions and 205 deletions

View File

@@ -137,14 +137,18 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a
}
}
char_u *ptr = line;
while (col <= wcol && *ptr != NUL) {
chartabsize_T cts;
init_chartabsize_arg(&cts, curwin, pos->lnum, 0, line, line);
while (cts.cts_vcol <= wcol && *cts.cts_ptr != NUL) {
// Count a tab for what it's worth (if list mode not on)
csize = win_lbr_chartabsize(curwin, line, ptr, col, &head);
MB_PTR_ADV(ptr);
col += csize;
csize = win_lbr_chartabsize(&cts, &head);
MB_PTR_ADV(cts.cts_ptr);
cts.cts_vcol += csize;
}
idx = (int)(ptr - line);
col = cts.cts_vcol;
idx = (int)(cts.cts_ptr - (char *)line);
clear_chartabsize_arg(&cts);
// Handle all the special cases. The virtual_active() check
// is needed to ensure that a virtual position off the end of
// a line has the correct indexing. The one_more comparison