diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-12-18 21:26:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-18 21:26:17 +0800 |
commit | 6b3ae24a70a15d485c6aadf059d3fa773f0da4cf (patch) | |
tree | 6258c0120ac4e41419388a69789fd2e0d24ec627 | |
parent | 1743359235206cbd9da2e0589f1caba37cce3b8c (diff) | |
download | rneovim-6b3ae24a70a15d485c6aadf059d3fa773f0da4cf.tar.gz rneovim-6b3ae24a70a15d485c6aadf059d3fa773f0da4cf.tar.bz2 rneovim-6b3ae24a70a15d485c6aadf059d3fa773f0da4cf.zip |
vim-patch:9.0.1072: screenpos() column result in fold may be too small (#21465)
Problem: screenpos() column result in fold may be too small.
Solution: Add space of 'number', sign column, etc. (closes vim/vim#11715)
https://github.com/vim/vim/commit/ba2d19193201277397c25c1f5a134ea042542555
-rw-r--r-- | src/nvim/move.c | 62 | ||||
-rw-r--r-- | src/nvim/testdir/test_cursor_func.vim | 8 |
2 files changed, 36 insertions, 34 deletions
diff --git a/src/nvim/move.c b/src/nvim/move.c index 60d2506e70..227e19bca3 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -937,41 +937,39 @@ void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, int *ccolp, bool existing_row = (pos->lnum > 0 && pos->lnum <= wp->w_buffer->b_ml.ml_line_count); - if (is_folded) { - row += local ? 0 : wp->w_winrow + wp->w_winrow_off; - coloff = (local ? 0 : wp->w_wincol + wp->w_wincol_off) + 1; - } else if ((local || visible_row) && existing_row) { - colnr_T off; - colnr_T col; - int width; - - getvcol(wp, pos, &scol, &ccol, &ecol); - - // similar to what is done in validate_cursor_col() - col = scol; - off = win_col_off(wp); - col += off; - width = wp->w_width - off + win_col_off2(wp); - - // 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 = visible_row ? ((col - wp->w_width) / width + 1) : 0; - col -= rowoff * width; - } - - col -= wp->w_leftcol; - - if (col >= 0 && col < wp->w_width && row + rowoff <= wp->w_height) { - coloff = col - scol + (local ? 0 : wp->w_wincol + wp->w_wincol_off) + 1; + if ((local || visible_row) && existing_row) { + const colnr_T off = win_col_off(wp); + if (is_folded) { row += local ? 0 : wp->w_winrow + wp->w_winrow_off; + coloff = (local ? 0 : wp->w_wincol + wp->w_wincol_off) + 1 + off; } else { - // character is left, right or below of the window - scol = ccol = ecol = 0; - if (local) { - coloff = col < 0 ? -1 : wp->w_width_inner + 1; + getvcol(wp, pos, &scol, &ccol, &ecol); + + // similar to what is done in validate_cursor_col() + colnr_T col = scol; + col += off; + int width = wp->w_width - off + win_col_off2(wp); + + // 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 = visible_row ? ((col - wp->w_width) / width + 1) : 0; + col -= rowoff * width; + } + + col -= wp->w_leftcol; + + if (col >= 0 && col < wp->w_width && row + rowoff <= wp->w_height) { + coloff = col - scol + (local ? 0 : wp->w_wincol + wp->w_wincol_off) + 1; + row += local ? 0 : wp->w_winrow + wp->w_winrow_off; } else { - row = rowoff = 0; + // character is left, right or below of the window + scol = ccol = ecol = 0; + if (local) { + coloff = col < 0 ? -1 : wp->w_width_inner + 1; + } else { + row = rowoff = 0; + } } } } diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim index 2151076cb9..bb8e7cd5c5 100644 --- a/src/nvim/testdir/test_cursor_func.vim +++ b/src/nvim/testdir/test_cursor_func.vim @@ -138,8 +138,12 @@ func Test_screenpos_fold() redraw call assert_equal(2, screenpos(1, 2, 1).row) call assert_equal(#{col: 1, row: 3, endcol: 1, curscol: 1}, screenpos(1, 3, 1)) - call assert_equal(3, screenpos(1, 4, 1).row) - call assert_equal(3, screenpos(1, 5, 1).row) + call assert_equal(#{col: 1, row: 3, endcol: 1, curscol: 1}, screenpos(1, 4, 1)) + call assert_equal(#{col: 1, row: 3, endcol: 1, curscol: 1}, screenpos(1, 5, 1)) + setlocal number + call assert_equal(#{col: 5, row: 3, endcol: 5, curscol: 5}, screenpos(1, 3, 1)) + call assert_equal(#{col: 5, row: 3, endcol: 5, curscol: 5}, screenpos(1, 4, 1)) + call assert_equal(#{col: 5, row: 3, endcol: 5, curscol: 5}, screenpos(1, 5, 1)) call assert_equal(4, screenpos(1, 6, 1).row) bwipe! endfunc |