diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2020-02-01 16:16:36 +0100 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2020-02-02 10:50:48 +0100 |
commit | 459a362cc140644d104de326258f9dfe75dbdcdf (patch) | |
tree | 2e43297946a5be6824ff349d16fdcc1174b63b63 /src | |
parent | 14a8b3b98c245087ef431070195f3a2fa3db16c0 (diff) | |
download | rneovim-459a362cc140644d104de326258f9dfe75dbdcdf.tar.gz rneovim-459a362cc140644d104de326258f9dfe75dbdcdf.tar.bz2 rneovim-459a362cc140644d104de326258f9dfe75dbdcdf.zip |
extmarks: fix crash due to invalid column values in inccommand preview
This used to use -1 and MAXCOL values. Make sure in range values are
used.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/extmark.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/nvim/extmark.c b/src/nvim/extmark.c index d60723c755..60ff5c3af9 100644 --- a/src/nvim/extmark.c +++ b/src/nvim/extmark.c @@ -699,21 +699,30 @@ void bufhl_add_hl_pos_offset(buf_T *buf, // TODO(bfredl): if decoration had blocky mode, we could avoid this loop for (linenr_T lnum = pos_start.lnum; lnum <= pos_end.lnum; lnum ++) { + int end_off = 0; if (pos_start.lnum < lnum && lnum < pos_end.lnum) { - hl_start = offset-1; - hl_end = MAXCOL; + // TODO(bfredl): This is quite ad-hoc, but the space between |num| and + // text being highlighted is the indication of \n being part of the + // substituted text. But it would be more consistent to highlight + // a space _after_ the previous line instead (like highlight EOL list + // char) + hl_start = MAX(offset-1, 0); + end_off = 1; + hl_end = 0; } else if (lnum == pos_start.lnum && lnum < pos_end.lnum) { hl_start = pos_start.col + offset; - hl_end = MAXCOL; + end_off = 1; + hl_end = 0; } else if (pos_start.lnum < lnum && lnum == pos_end.lnum) { - hl_start = offset-1; + hl_start = MAX(offset-1, 0); hl_end = pos_end.col + offset; } else if (pos_start.lnum == lnum && pos_end.lnum == lnum) { hl_start = pos_start.col + offset; hl_end = pos_end.col + offset; } (void)extmark_add_decoration(buf, (uint64_t)src_id, hl_id, - (int)lnum-1, hl_start, (int)lnum-1, hl_end, + (int)lnum-1, hl_start, + (int)lnum-1+end_off, hl_end, VIRTTEXT_EMPTY); } } |