mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
vim-patch:8.2.4389: screenpos() does not handle a position in a closed fold
Problem: screenpos() does not handle a position in a closed fold.
Solution: Check if the position is inside a closed fold. (closes vim/vim#9778)
4556a2e868
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -920,9 +920,12 @@ void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, int *ccolp,
|
|||||||
int rowoff = 0;
|
int rowoff = 0;
|
||||||
colnr_T coloff = 0;
|
colnr_T coloff = 0;
|
||||||
bool visible_row = false;
|
bool visible_row = false;
|
||||||
|
bool is_folded = false;
|
||||||
|
|
||||||
if (pos->lnum >= wp->w_topline && pos->lnum <= wp->w_botline) {
|
if (pos->lnum >= wp->w_topline && pos->lnum <= wp->w_botline) {
|
||||||
row = plines_m_win(wp, wp->w_topline, pos->lnum - 1) + 1;
|
linenr_T lnum = pos->lnum;
|
||||||
|
is_folded = hasFoldingWin(wp, lnum, &lnum, NULL, true, NULL);
|
||||||
|
row = plines_m_win(wp, wp->w_topline, lnum - 1) + 1;
|
||||||
visible_row = true;
|
visible_row = true;
|
||||||
} else if (!local || pos->lnum < wp->w_topline) {
|
} else if (!local || pos->lnum < wp->w_topline) {
|
||||||
row = 0;
|
row = 0;
|
||||||
@@ -933,7 +936,10 @@ void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, int *ccolp,
|
|||||||
bool existing_row = (pos->lnum > 0
|
bool existing_row = (pos->lnum > 0
|
||||||
&& pos->lnum <= wp->w_buffer->b_ml.ml_line_count);
|
&& pos->lnum <= wp->w_buffer->b_ml.ml_line_count);
|
||||||
|
|
||||||
if ((local || visible_row) && existing_row) {
|
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 off;
|
||||||
colnr_T col;
|
colnr_T col;
|
||||||
int width;
|
int width;
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
" Tests for cursor() and other functions that get/set the cursor position
|
" Tests for cursor() and other functions that get/set the cursor position
|
||||||
|
|
||||||
|
source check.vim
|
||||||
|
|
||||||
func Test_wrong_arguments()
|
func Test_wrong_arguments()
|
||||||
call assert_fails('call cursor(1. 3)', 'E474:')
|
call assert_fails('call cursor(1. 3)', 'E474:')
|
||||||
|
call assert_fails('call cursor(v:_null_list)', 'E474:')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_move_cursor()
|
func Test_move_cursor()
|
||||||
@@ -118,14 +121,29 @@ func Test_screenpos()
|
|||||||
bwipe!
|
bwipe!
|
||||||
set display&
|
set display&
|
||||||
|
|
||||||
call assert_equal({'col': 1, 'row': 1, 'endcol': 1, 'curscol': 1}, screenpos(win_getid(), 1, 1))
|
call assert_equal(#{col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(win_getid(), 1, 1))
|
||||||
" nmenu WinBar.TEST :
|
" nmenu WinBar.TEST :
|
||||||
setlocal winbar=TEST
|
setlocal winbar=TEST
|
||||||
call assert_equal({'col': 1, 'row': 2, 'endcol': 1, 'curscol': 1}, screenpos(win_getid(), 1, 1))
|
call assert_equal(#{col: 1, row: 2, endcol: 1, curscol: 1}, screenpos(win_getid(), 1, 1))
|
||||||
" nunmenu WinBar.TEST
|
" nunmenu WinBar.TEST
|
||||||
setlocal winbar&
|
setlocal winbar&
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_screenpos_fold()
|
||||||
|
CheckFeature folding
|
||||||
|
|
||||||
|
enew!
|
||||||
|
call setline(1, range(10))
|
||||||
|
3,5fold
|
||||||
|
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(4, screenpos(1, 6, 1).row)
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_screenpos_number()
|
func Test_screenpos_number()
|
||||||
rightbelow new
|
rightbelow new
|
||||||
rightbelow 73vsplit
|
rightbelow 73vsplit
|
||||||
|
Reference in New Issue
Block a user