aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/move.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/move.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/move.c')
-rw-r--r--src/nvim/move.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/nvim/move.c b/src/nvim/move.c
index 25dee0a114..dfd2bf795d 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -1142,13 +1142,17 @@ void f_screenpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
/// returned.
static int virtcol2col(win_T *wp, linenr_T lnum, int vcol)
{
- int offset = vcol2col(wp, lnum, vcol);
+ int offset = vcol2col(wp, lnum, vcol - 1);
char *line = ml_get_buf(wp->w_buffer, lnum);
char *p = line + offset;
- // For a multibyte character, need to return the column number of the first byte.
- MB_PTR_BACK(line, p);
-
+ if (*p == NUL) {
+ if (p == line) { // empty line
+ return 0;
+ }
+ // Move to the first byte of the last char.
+ MB_PTR_BACK(line, p);
+ }
return (int)(p - line + 1);
}