aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/mouse.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/mouse.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/mouse.c')
-rw-r--r--src/nvim/mouse.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c
index 3dfbeec048..5ebe97aa61 100644
--- a/src/nvim/mouse.c
+++ b/src/nvim/mouse.c
@@ -631,14 +631,16 @@ colnr_T vcol2col(win_T *const wp, const linenr_T lnum, const colnr_T vcol)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
// try to advance to the specified column
- char_u *ptr = ml_get_buf(wp->w_buffer, lnum, false);
- char_u *const line = ptr;
- colnr_T count = 0;
- while (count < vcol && *ptr != NUL) {
- count += win_lbr_chartabsize(wp, line, ptr, count, NULL);
- MB_PTR_ADV(ptr);
- }
- return (colnr_T)(ptr - line);
+ char_u *line = ml_get_buf(wp->w_buffer, lnum, false);
+ chartabsize_T cts;
+ init_chartabsize_arg(&cts, wp, lnum, 0, line, line);
+ while (cts.cts_vcol < vcol && *cts.cts_ptr != NUL) {
+ cts.cts_vcol += win_lbr_chartabsize(&cts, NULL);
+ MB_PTR_ADV(cts.cts_ptr);
+ }
+ clear_chartabsize_arg(&cts);
+
+ return (colnr_T)((char_u *)cts.cts_ptr - line);
}
/// Set UI mouse depending on current mode and 'mouse'.
@@ -667,7 +669,7 @@ static colnr_T scroll_line_len(linenr_T lnum)
char_u *line = ml_get(lnum);
if (*line != NUL) {
for (;;) {
- int numchar = win_chartabsize(curwin, line, col);
+ int numchar = win_chartabsize(curwin, (char *)line, col);
MB_PTR_ADV(line);
if (*line == NUL) { // don't count the last character
break;
@@ -790,7 +792,7 @@ static int mouse_adjust_click(win_T *wp, int row, int col)
// checked for concealed characters.
vcol = 0;
while (vcol < offset && *ptr != NUL) {
- vcol += win_chartabsize(curwin, ptr, vcol);
+ vcol += win_chartabsize(curwin, (char *)ptr, vcol);
ptr += utfc_ptr2len((char *)ptr);
}
@@ -801,7 +803,7 @@ static int mouse_adjust_click(win_T *wp, int row, int col)
vcol = offset;
ptr_end = ptr_row_offset;
while (vcol < col && *ptr_end != NUL) {
- vcol += win_chartabsize(curwin, ptr_end, vcol);
+ vcol += win_chartabsize(curwin, (char *)ptr_end, vcol);
ptr_end += utfc_ptr2len((char *)ptr_end);
}
@@ -816,7 +818,7 @@ static int mouse_adjust_click(win_T *wp, int row, int col)
#define DECR() nudge--; ptr_end -= utfc_ptr2len((char *)ptr_end)
while (ptr < ptr_end && *ptr != NUL) {
- cwidth = win_chartabsize(curwin, ptr, vcol);
+ cwidth = win_chartabsize(curwin, (char *)ptr, vcol);
vcol += cwidth;
if (cwidth > 1 && *ptr == '\t' && nudge > 0) {
// A tab will "absorb" any previous adjustments.