diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-09-21 10:20:30 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-09-21 11:13:48 +0800 |
commit | e25cf47ad3e10e0e1ae2b2376d898382af5b1e26 (patch) | |
tree | f4273000589b33ed5b98990e22d766f904428de4 /src/nvim/mouse.c | |
parent | acc32f20bedd611a582aedf08d64ad66d2a19d3b (diff) | |
download | rneovim-e25cf47ad3e10e0e1ae2b2376d898382af5b1e26.tar.gz rneovim-e25cf47ad3e10e0e1ae2b2376d898382af5b1e26.tar.bz2 rneovim-e25cf47ad3e10e0e1ae2b2376d898382af5b1e26.zip |
fix(mouse): click on empty line with 'foldcolumn'
Diffstat (limited to 'src/nvim/mouse.c')
-rw-r--r-- | src/nvim/mouse.c | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index c4a31e0783..33d7bc2e51 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -1861,44 +1861,47 @@ static void mouse_check_grid(colnr_T *vcolp, int *flagsp) int start_row = 0; int start_col = 0; grid_adjust(&gp, &start_row, &start_col); - if (gp->handle != click_grid) { + if (gp->handle != click_grid || gp->chars == NULL) { return; } click_row += start_row; click_col += start_col; + if (click_row < 0 || click_row >= gp->rows + || click_col < 0 || click_col >= gp->cols) { + return; + } - colnr_T col_from_screen = -1; + const size_t off = gp->line_offset[click_row] + (size_t)click_col; + colnr_T col_from_screen = gp->vcols[off]; - if (gp->chars != NULL - && click_row >= 0 && click_row < gp->rows - && click_col >= 0 && click_col < gp->cols) { - const size_t off = gp->line_offset[click_row] + (size_t)click_col; - col_from_screen = gp->vcols[off]; - - if (col_from_screen == MAXCOL) { - // When clicking after end of line, still need to set correct curswant - size_t off_l = gp->line_offset[click_row] + (size_t)start_col; - if (gp->vcols[off_l] < MAXCOL) { - // Binary search to find last char in line - size_t off_r = off; - while (off_l < off_r) { - size_t off_m = (off_l + off_r + 1) / 2; - if (gp->vcols[off_m] < MAXCOL) { - off_l = off_m; - } else { - off_r = off_m - 1; - } + if (col_from_screen == MAXCOL) { + // When clicking after end of line, still need to set correct curswant + size_t off_l = gp->line_offset[click_row] + (size_t)start_col; + if (gp->vcols[off_l] < MAXCOL) { + // Binary search to find last char in line + size_t off_r = off; + while (off_l < off_r) { + size_t off_m = (off_l + off_r + 1) / 2; + if (gp->vcols[off_m] < MAXCOL) { + off_l = off_m; + } else { + off_r = off_m - 1; } - *vcolp = gp->vcols[off_r] + (int)(off - off_r); - } else { - // Clicking on an empty line - *vcolp = click_col - start_col; } - } else if (col_from_screen >= 0) { - // Use the virtual column from vcols[], it is accurate also after - // concealed characters. - *vcolp = col_from_screen; + colnr_T eol_vcol = gp->vcols[off_r]; + assert(eol_vcol < MAXCOL); + // This may be -2 or -3 with 'foldcolumn' and empty line. + // In that case set it to -1 as it's just before start of line. + eol_vcol = MAX(eol_vcol, -1); + *vcolp = eol_vcol + (int)(off - off_r); + } else { + // Clicking on an empty line + *vcolp = click_col - start_col; } + } else if (col_from_screen >= 0) { + // Use the virtual column from vcols[], it is accurate also after + // concealed characters. + *vcolp = col_from_screen; } if (col_from_screen == -2) { |