diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-08-27 11:28:11 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2022-08-29 12:05:34 +0200 |
commit | ea4e9c71ccaf406fe7aa6b47d461cdab2d6c01e9 (patch) | |
tree | d8c14449741cdfcbf3fcb65d518a7ee0a15a70bb /src/nvim/cursor.c | |
parent | 7a9b5937966d3db852c84b8eb232e77d92d3c355 (diff) | |
download | rneovim-ea4e9c71ccaf406fe7aa6b47d461cdab2d6c01e9.tar.gz rneovim-ea4e9c71ccaf406fe7aa6b47d461cdab2d6c01e9.tar.bz2 rneovim-ea4e9c71ccaf406fe7aa6b47d461cdab2d6c01e9.zip |
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.
Diffstat (limited to 'src/nvim/cursor.c')
-rw-r--r-- | src/nvim/cursor.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 14ebc11cbf..ed0488cf76 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -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 |