Skip to content

Commit

Permalink
patch 9.1.0759: screenpos() may return invalid position
Browse files Browse the repository at this point in the history
Problem:  screenpos() may return invalid position
          after switching buffers (Greg Hurrell)
Solution: reset w_leftcol if wrapping has been set
          after copying wrap option

fixes: #15792
closes: #15803

Signed-off-by: Christian Brabandt <[email protected]>
  • Loading branch information
chrisbra committed Oct 5, 2024
1 parent 7c3f9af commit b065a10
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -6737,6 +6737,11 @@ win_copy_options(win_T *wp_from, win_T *wp_to)
void
after_copy_winopt(win_T *wp)
{
// Set w_leftcol or w_skipcol to zero.
if (wp->w_p_wrap)
wp->w_leftcol = 0;
else
wp->w_skipcol = 0;
#ifdef FEAT_LINEBREAK
briopt_check(wp);
#endif
Expand Down
15 changes: 15 additions & 0 deletions src/testdir/test_cursor_func.vim
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,21 @@ func Test_screenpos_number()
bwipe!
endfunc

func Test_screenpos_edit_newfile()
new
20vsp
setl nowrap
call setline(1, 'abcdefghijklmnopqrstuvwxyz')
call cursor(1, 10)
norm! 5zl
call assert_equal(#{col: 5, row: 1, endcol: 5, curscol: 5}, screenpos(win_getid(), 1, 10))
enew!
call assert_equal(1, &l:wrap)
call assert_equal(#{col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(win_getid(), 1, 1))

bwipe!
endfunc

" Save the visual start character position
func SaveVisualStartCharPos()
call add(g:VisualStartPos, getcharpos('v'))
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
759,
/**/
758,
/**/
Expand Down

0 comments on commit b065a10

Please sign in to comment.