aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/getchar.c
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2022-08-27 11:28:11 +0200
committerbfredl <bjorn.linse@gmail.com>2022-08-29 12:05:34 +0200
commitea4e9c71ccaf406fe7aa6b47d461cdab2d6c01e9 (patch)
treed8c14449741cdfcbf3fcb65d518a7ee0a15a70bb /src/nvim/getchar.c
parent7a9b5937966d3db852c84b8eb232e77d92d3c355 (diff)
downloadrneovim-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/getchar.c')
-rw-r--r--src/nvim/getchar.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index c1c5680cb0..f875fda13d 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -2547,7 +2547,7 @@ static int vgetorpeek(bool advance)
&& (State & MODE_INSERT)
&& (p_timeout || (keylen == KEYLEN_PART_KEY && p_ttimeout))
&& (c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len, 3, 25L)) == 0) {
- colnr_T col = 0, vcol;
+ colnr_T col = 0;
char_u *ptr;
if (mode_displayed) {
@@ -2565,15 +2565,20 @@ static int vgetorpeek(bool advance)
// We are expecting to truncate the trailing
// white-space, so find the last non-white
// character -- webb
- col = vcol = curwin->w_wcol = 0;
+ curwin->w_wcol = 0;
ptr = get_cursor_line_ptr();
- while (col < curwin->w_cursor.col) {
- if (!ascii_iswhite(ptr[col])) {
- curwin->w_wcol = vcol;
+ chartabsize_T cts;
+ init_chartabsize_arg(&cts, curwin,
+ curwin->w_cursor.lnum, 0, ptr, ptr);
+ while ((char_u *)cts.cts_ptr < ptr + curwin->w_cursor.col) {
+ if (!ascii_iswhite(*cts.cts_ptr)) {
+ curwin->w_wcol = cts.cts_vcol;
}
- vcol += lbr_chartabsize(ptr, ptr + col, vcol);
- col += utfc_ptr2len((char *)ptr + col);
+ cts.cts_vcol += lbr_chartabsize(&cts);
+ cts.cts_ptr += utfc_ptr2len(cts.cts_ptr);
}
+ clear_chartabsize_arg(&cts);
+
curwin->w_wrow = curwin->w_cline_row
+ curwin->w_wcol / curwin->w_width_inner;
curwin->w_wcol %= curwin->w_width_inner;