aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/drawline.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-03-17 07:26:39 +0800
committerGitHub <noreply@github.com>2024-03-17 07:26:39 +0800
commitd114dbe9f79c1382298b04319b7ded88e95e3ee8 (patch)
treea3ed5239b72332bef8e42afa2b9ba095c74d7afe /src/nvim/drawline.c
parent34b57508a78b0a980e898ee35d950db0a90368ca (diff)
downloadrneovim-d114dbe9f79c1382298b04319b7ded88e95e3ee8.tar.gz
rneovim-d114dbe9f79c1382298b04319b7ded88e95e3ee8.tar.bz2
rneovim-d114dbe9f79c1382298b04319b7ded88e95e3ee8.zip
vim-patch:9.1.0184: Cursor pos wrong when clicking with conceal and wrap (#27890)
Problem: Cursor position wrong when clicking with conceal and wrap. Solution: Use the virtual column of the last char for ScreenCols[] in boguscols. Remove use of MAXCOL in ScreenCols[]. Rename third argument of wlv_screen_line() to "clear_end" as that's clearer what it does (zeertzjq). related: 14192 closes: vim/vim#14200 https://github.com/vim/vim/commit/d0c1b7723f7e73763597af2f97a53d94ab7ed020 Rename win_put_linebuf() to wlv_put_linebuf().
Diffstat (limited to 'src/nvim/drawline.c')
-rw-r--r--src/nvim/drawline.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c
index ffe2253cf1..816eb8a674 100644
--- a/src/nvim/drawline.c
+++ b/src/nvim/drawline.c
@@ -300,6 +300,7 @@ static void draw_virt_text(win_T *wp, buf_T *buf, int col_off, int *end_col, int
if (vt->pos == kVPosEndOfLine && do_eol) {
state->eol_col = col + 1;
}
+ // TODO(zeertzjq): set values in linebuf_vcol[]
*end_col = MAX(*end_col, col);
}
if (!vt || !(vt->flags & kVTRepeatLinebreak)) {
@@ -1549,7 +1550,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
// When only updating the columns and that's done, stop here.
if (col_rows > 0) {
- win_put_linebuf(wp, wlv.row, wlv.off, wlv.off, bg_attr, false);
+ wlv_put_linebuf(wp, &wlv, wlv.off, false, bg_attr, 0);
// Need to update more screen lines if:
// - 'statuscolumn' needs to be drawn, or
// - LineNrAbove or LineNrBelow is used, or
@@ -1606,7 +1607,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
&& lnum == wp->w_cursor.lnum && wlv.vcol >= wp->w_virtcol) {
draw_virt_text(wp, buf, win_col_offset, &wlv.col, wlv.row);
// don't clear anything after wlv.col
- win_put_linebuf(wp, wlv.row, wlv.col, wlv.col, bg_attr, false);
+ wlv_put_linebuf(wp, &wlv, wlv.col, false, bg_attr, 0);
// Pretend we have finished updating the window. Except when
// 'cursorcolumn' is set.
if (wp->w_p_cuc) {
@@ -2539,7 +2540,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
: wlv.char_attr;
linebuf_attr[wlv.off] = eol_attr;
- linebuf_vcol[wlv.off] = MAXCOL;
+ linebuf_vcol[wlv.off] = wlv.vcol;
wlv.col++;
wlv.off++;
wlv.vcol++;
@@ -2595,7 +2596,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
while (wlv.col < grid->cols) {
linebuf_char[wlv.off] = schar_from_ascii(' ');
- linebuf_vcol[wlv.off] = MAXCOL;
+ linebuf_vcol[wlv.off] = wlv.vcol;
wlv.col++;
advance_color_col(&wlv, vcol_hlc(wlv));
@@ -2638,7 +2639,9 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
draw_virt_text_item(buf, win_col_offset, fold_vt, kHlModeCombine, grid->cols, 0);
}
draw_virt_text(wp, buf, win_col_offset, &wlv.col, wlv.row);
- win_put_linebuf(wp, wlv.row, wlv.col, grid->cols, bg_attr, false);
+ // Set increasing virtual columns in grid->vcols[] to set correct curswant
+ // (or "coladd" for 'virtualedit') when clicking after end of line.
+ wlv_put_linebuf(wp, &wlv, wlv.col, true, bg_attr, SLF_INC_VCOL);
wlv.row++;
// Update w_cline_height and w_cline_folded if the cursor line was
@@ -2869,7 +2872,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
while (draw_col < grid->cols) {
linebuf_char[wlv.off] = schar_from_char(' ');
linebuf_attr[wlv.off] = attr;
- linebuf_vcol[wlv.off] = MAXCOL; // TODO(zeertzjq): this is wrong
+ linebuf_vcol[wlv.off] = wlv.vcol - 1;
wlv.off++;
draw_col++;
}
@@ -2882,7 +2885,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
draw_virt_text(wp, buf, win_col_offset, &draw_col, wlv.row);
}
- win_put_linebuf(wp, wlv.row, draw_col, grid->cols, bg_attr, wrap);
+ wlv_put_linebuf(wp, &wlv, draw_col, true, bg_attr, wrap ? SLF_WRAP : 0);
if (wrap) {
ScreenGrid *current_grid = grid;
int current_row = wlv.row;
@@ -2942,18 +2945,28 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
return wlv.row;
}
-static void win_put_linebuf(win_T *wp, int row, int endcol, int clear_width, int bg_attr, bool wrap)
+/// Call grid_put_linebuf() using values from "wlv".
+/// Also takes care of putting "<<<" on the first line for 'smoothscroll'
+/// when 'showbreak' is not set.
+///
+/// @param clear_end clear until the end of the screen line.
+/// @param flags for grid_put_linebuf(), but shouldn't contain SLF_RIGHTLEFT.
+static void wlv_put_linebuf(win_T *wp, const winlinevars_T *wlv, int endcol, bool clear_end,
+ int bg_attr, int flags)
{
ScreenGrid *grid = &wp->w_grid;
int startcol = 0;
+ int clear_width = clear_end ? grid->cols : endcol;
+ assert(!(flags & SLF_RIGHTLEFT));
if (wp->w_p_rl) {
linebuf_mirror(&startcol, &endcol, &clear_width, grid->cols);
+ flags |= SLF_RIGHTLEFT;
}
// Take care of putting "<<<" on the first line for 'smoothscroll'.
- if (row == 0 && wp->w_skipcol > 0
+ if (wlv->row == 0 && wp->w_skipcol > 0
// do not overwrite the 'showbreak' text with "<<<"
&& *get_showbreak_value(wp) == NUL
// do not overwrite the 'listchars' "precedes" text with "<<<"
@@ -2978,7 +2991,8 @@ static void win_put_linebuf(win_T *wp, int row, int endcol, int clear_width, int
}
}
+ int row = wlv->row;
int coloff = 0;
grid_adjust(&grid, &row, &coloff);
- grid_put_linebuf(grid, row, coloff, startcol, endcol, clear_width, wp->w_p_rl, bg_attr, wrap);
+ grid_put_linebuf(grid, row, coloff, startcol, endcol, clear_width, bg_attr, wlv->vcol - 1, flags);
}