1
0
forked from aniani/vim

patch 9.0.1729: screenpos() wrong when w_skipcol and cpoptions+=n

Problem:    screenpos() wrong result with w_skipcol and cpoptions+=n
Solution:   Use adjust_plines_for_skipcol() instead of subtracting
            w_skipcol.

closes: #12625

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
This commit is contained in:
zeertzjq
2023-08-17 22:58:53 +02:00
committed by Christian Brabandt
parent 825cf813fa
commit bfe377b8f2
7 changed files with 87 additions and 46 deletions

View File

@@ -1356,7 +1356,10 @@ curs_columns(
// don't skip more than necessary
if (n > p_lines - curwin->w_height + 1)
n = p_lines - curwin->w_height + 1;
curwin->w_skipcol = n * width2;
if (n > 0)
curwin->w_skipcol = width1 + (n - 1) * width2;
else
curwin->w_skipcol = 0;
}
else if (extra == 1)
{
@@ -1443,7 +1446,6 @@ textpos2screenpos(
{
colnr_T scol = 0, ccol = 0, ecol = 0;
int row = 0;
int rowoff = 0;
colnr_T coloff = 0;
if (pos->lnum >= wp->w_topline && pos->lnum <= wp->w_botline)
@@ -1456,7 +1458,10 @@ textpos2screenpos(
is_folded = hasFoldingWin(wp, lnum, &lnum, NULL, TRUE, NULL);
#endif
row = plines_m_win(wp, wp->w_topline, lnum - 1) + 1;
row = plines_m_win(wp, wp->w_topline, lnum - 1, FALSE) + 1;
// "row" should be the screen line where line "lnum" begins, which can
// be negative if "lnum" is "w_topline" and "w_skipcol" is non-zero.
row = adjust_plines_for_skipcol(wp, row);
#ifdef FEAT_DIFF
// Add filler lines above this buffer line.
@@ -1481,32 +1486,30 @@ textpos2screenpos(
col += off;
width = wp->w_width - off + win_col_off2(wp);
if (lnum == wp->w_topline)
col -= wp->w_skipcol;
// long line wrapping, adjust row
if (wp->w_p_wrap
&& col >= (colnr_T)wp->w_width
&& width > 0)
{
// use same formula as what is used in curs_columns()
rowoff = ((col - wp->w_width) / width + 1);
int rowoff = ((col - wp->w_width) / width + 1);
col -= rowoff * width;
row += rowoff;
}
col -= wp->w_leftcol;
if (col >= wp->w_width)
col = -1;
if (col >= 0 && row + rowoff <= wp->w_height)
if (col >= 0 && row > 0 && row <= wp->w_height)
{
coloff = col - scol + wp->w_wincol + 1;
row += W_WINROW(wp);
}
else
// character is left, right or below of the window
row = rowoff = scol = ccol = ecol = 0;
// character is out of the window
row = scol = ccol = ecol = 0;
}
}
*rowp = row + rowoff;
*rowp = row;
*scolp = scol + coloff;
*ccolp = ccol + coloff;
*ecolp = ecol + coloff;