diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-07-12 08:50:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-12 08:50:34 +0800 |
commit | bf52fb7193ca08ceca292cfca9156380a6661979 (patch) | |
tree | 50fd21043367b77ed5e17f6f39c9e0cbe99e47b6 /src | |
parent | bf5703042b50c858bfc4633b1807c961089ec5e1 (diff) | |
download | rneovim-bf52fb7193ca08ceca292cfca9156380a6661979.tar.gz rneovim-bf52fb7193ca08ceca292cfca9156380a6661979.tar.bz2 rneovim-bf52fb7193ca08ceca292cfca9156380a6661979.zip |
fix(mouse): copy the line before syntax matching (#24320)
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/mouse.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index 9c6acf9f80..aca15eb0e2 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -1692,7 +1692,8 @@ static int mouse_adjust_click(win_T *wp, int row, int col) // highlighting the second byte, not the ninth. linenr_T lnum = wp->w_cursor.lnum; - char *line = ml_get(lnum); + // Make a copy of the line, because syntax matching may free it. + char *line = xstrdup(ml_get(lnum)); char *ptr = line; char *ptr_end; char *ptr_row_offset = line; // Where we begin adjusting `ptr_end` @@ -1733,8 +1734,8 @@ static int mouse_adjust_click(win_T *wp, int row, int col) vcol = offset; -#define INCR() nudge++; ptr_end += utfc_ptr2len((char *)ptr_end) -#define DECR() nudge--; ptr_end -= utfc_ptr2len((char *)ptr_end) +#define INCR() nudge++; ptr_end += utfc_ptr2len(ptr_end) +#define DECR() nudge--; ptr_end -= utfc_ptr2len(ptr_end) while (ptr < ptr_end && *ptr != NUL) { int cwidth = win_chartabsize(curwin, ptr, vcol); @@ -1776,6 +1777,7 @@ static int mouse_adjust_click(win_T *wp, int row, int col) ptr += utfc_ptr2len(ptr); } + xfree(line); return col + nudge; } |