aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/mouse.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-10-14 19:18:25 +0800
committerGitHub <noreply@github.com>2023-10-14 19:18:25 +0800
commitbcda800933f6de09392c3c91e290077952989722 (patch)
treeb4bababb6bb9aa3f80375db4feab2ccffd32c594 /src/nvim/mouse.c
parent99b1163b5ae7a2f199803541c09f3da80547b40c (diff)
downloadrneovim-bcda800933f6de09392c3c91e290077952989722.tar.gz
rneovim-bcda800933f6de09392c3c91e290077952989722.tar.bz2
rneovim-bcda800933f6de09392c3c91e290077952989722.zip
vim-patch:9.0.2022: getmousepos() returns wrong index for TAB char (#25636)
Problem: When clicking in the middle of a TAB, getmousepos() returns the column of the next char instead of the TAB. Solution: Break out of the loop when the vcol to find is inside current char. Fix invalid memory access when calling virtcol2col() on an empty line. closes: vim/vim#13321 https://github.com/vim/vim/commit/b583eda7031b1f6a3469a2537d0c10ca5fa5568e
Diffstat (limited to 'src/nvim/mouse.c')
-rw-r--r--src/nvim/mouse.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c
index 0433031393..75c399bcad 100644
--- a/src/nvim/mouse.c
+++ b/src/nvim/mouse.c
@@ -1754,7 +1754,7 @@ static win_T *mouse_find_grid_win(int *gridp, int *rowp, int *colp)
}
/// Convert a virtual (screen) column to a character column.
-/// The first column is one.
+/// The first column is zero.
colnr_T vcol2col(win_T *const wp, const linenr_T lnum, const colnr_T vcol)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
@@ -1763,7 +1763,11 @@ colnr_T vcol2col(win_T *const wp, const linenr_T lnum, const colnr_T vcol)
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);
+ int size = win_lbr_chartabsize(&cts, NULL);
+ if (cts.cts_vcol + size > vcol) {
+ break;
+ }
+ cts.cts_vcol += size;
MB_PTR_ADV(cts.cts_ptr);
}
clear_chartabsize_arg(&cts);