Skip to content

Commit a732285

Browse files
committed
updated for version 7.3.239
Problem: Python corrects the cursor column without taking 'virtualedit' into account. (lilydjwg) Solution: Call check_cursor_col_win().
1 parent f562b94 commit a732285

File tree

7 files changed

+38
-28
lines changed

7 files changed

+38
-28
lines changed

src/if_py_both.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ WindowSetattr(PyObject *self, char *name, PyObject *val)
534534
{
535535
long lnum;
536536
long col;
537-
long len;
538537

539538
if (!PyArg_Parse(val, "(ll)", &lnum, &col))
540539
return -1;
@@ -549,18 +548,15 @@ WindowSetattr(PyObject *self, char *name, PyObject *val)
549548
if (VimErrorCheck())
550549
return -1;
551550

552-
/* When column is out of range silently correct it. */
553-
len = (long)STRLEN(ml_get_buf(this->win->w_buffer, lnum, FALSE));
554-
if (col > len)
555-
col = len;
556-
557551
this->win->w_cursor.lnum = lnum;
558552
this->win->w_cursor.col = col;
559553
#ifdef FEAT_VIRTUALEDIT
560554
this->win->w_cursor.coladd = 0;
561555
#endif
562-
update_screen(VALID);
556+
/* When column is out of range silently correct it. */
557+
check_cursor_col_win(this->win);
563558

559+
update_screen(VALID);
564560
return 0;
565561
}
566562
else if (strcmp(name, "height") == 0)

src/mbyte.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3563,15 +3563,16 @@ dbcs_screen_tail_off(base, p)
35633563
void
35643564
mb_adjust_cursor()
35653565
{
3566-
mb_adjustpos(&curwin->w_cursor);
3566+
mb_adjustpos(curbuf, &curwin->w_cursor);
35673567
}
35683568

35693569
/*
35703570
* Adjust position "*lp" to point to the first byte of a multi-byte character.
35713571
* If it points to a tail byte it's moved backwards to the head byte.
35723572
*/
35733573
void
3574-
mb_adjustpos(lp)
3574+
mb_adjustpos(buf, lp)
3575+
buf_T *buf;
35753576
pos_T *lp;
35763577
{
35773578
char_u *p;
@@ -3582,7 +3583,7 @@ mb_adjustpos(lp)
35823583
#endif
35833584
)
35843585
{
3585-
p = ml_get(lp->lnum);
3586+
p = ml_get_buf(buf, lp->lnum, FALSE);
35863587
lp->col -= (*mb_head_off)(p, p + lp->col);
35873588
#ifdef FEAT_VIRTUALEDIT
35883589
/* Reset "coladd" when the cursor would be on the right half of a

src/misc2.c

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ coladvance2(pos, addspaces, finetune, wcol)
333333
#ifdef FEAT_MBYTE
334334
/* prevent from moving onto a trail byte */
335335
if (has_mbyte)
336-
mb_adjustpos(pos);
336+
mb_adjustpos(curbuf, pos);
337337
#endif
338338

339339
if (col < wcol)
@@ -543,17 +543,27 @@ check_cursor_lnum()
543543
*/
544544
void
545545
check_cursor_col()
546+
{
547+
check_cursor_col_win(curwin);
548+
}
549+
550+
/*
551+
* Make sure win->w_cursor.col is valid.
552+
*/
553+
void
554+
check_cursor_col_win(win)
555+
win_T *win;
546556
{
547557
colnr_T len;
548558
#ifdef FEAT_VIRTUALEDIT
549-
colnr_T oldcol = curwin->w_cursor.col;
550-
colnr_T oldcoladd = curwin->w_cursor.col + curwin->w_cursor.coladd;
559+
colnr_T oldcol = win->w_cursor.col;
560+
colnr_T oldcoladd = win->w_cursor.col + win->w_cursor.coladd;
551561
#endif
552562

553-
len = (colnr_T)STRLEN(ml_get_curline());
563+
len = (colnr_T)STRLEN(ml_get_buf(win->w_buffer, win->w_cursor.lnum, FALSE));
554564
if (len == 0)
555-
curwin->w_cursor.col = 0;
556-
else if (curwin->w_cursor.col >= len)
565+
win->w_cursor.col = 0;
566+
else if (win->w_cursor.col >= len)
557567
{
558568
/* Allow cursor past end-of-line when:
559569
* - in Insert mode or restarting Insert mode
@@ -567,33 +577,33 @@ check_cursor_col()
567577
|| (ve_flags & VE_ONEMORE)
568578
#endif
569579
|| virtual_active())
570-
curwin->w_cursor.col = len;
580+
win->w_cursor.col = len;
571581
else
572582
{
573-
curwin->w_cursor.col = len - 1;
583+
win->w_cursor.col = len - 1;
574584
#ifdef FEAT_MBYTE
575-
/* prevent cursor from moving on the trail byte */
585+
/* Move the cursor to the head byte. */
576586
if (has_mbyte)
577-
mb_adjust_cursor();
587+
mb_adjustpos(win->w_buffer, &win->w_cursor);
578588
#endif
579589
}
580590
}
581-
else if (curwin->w_cursor.col < 0)
582-
curwin->w_cursor.col = 0;
591+
else if (win->w_cursor.col < 0)
592+
win->w_cursor.col = 0;
583593

584594
#ifdef FEAT_VIRTUALEDIT
585595
/* If virtual editing is on, we can leave the cursor on the old position,
586596
* only we must set it to virtual. But don't do it when at the end of the
587597
* line. */
588598
if (oldcol == MAXCOL)
589-
curwin->w_cursor.coladd = 0;
599+
win->w_cursor.coladd = 0;
590600
else if (ve_flags == VE_ALL)
591601
{
592-
if (oldcoladd > curwin->w_cursor.col)
593-
curwin->w_cursor.coladd = oldcoladd - curwin->w_cursor.col;
602+
if (oldcoladd > win->w_cursor.col)
603+
win->w_cursor.coladd = oldcoladd - win->w_cursor.col;
594604
else
595605
/* avoid weird number when there is a miscalculation or overflow */
596-
curwin->w_cursor.coladd = 0;
606+
win->w_cursor.coladd = 0;
597607
}
598608
#endif
599609
}

src/normal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8774,7 +8774,7 @@ unadjust_for_sel()
87748774
{
87758775
--pp->col;
87768776
#ifdef FEAT_MBYTE
8777-
mb_adjustpos(pp);
8777+
mb_adjustpos(curbuf, pp);
87788778
#endif
87798779
}
87808780
else if (pp->lnum > 1)

src/proto/mbyte.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void utf_find_illegal __ARGS((void));
5656
int utf_valid_string __ARGS((char_u *s, char_u *end));
5757
int dbcs_screen_tail_off __ARGS((char_u *base, char_u *p));
5858
void mb_adjust_cursor __ARGS((void));
59-
void mb_adjustpos __ARGS((pos_T *lp));
59+
void mb_adjustpos __ARGS((buf_T *buf, pos_T *lp));
6060
char_u *mb_prevptr __ARGS((char_u *line, char_u *p));
6161
int mb_charlen __ARGS((char_u *str));
6262
int mb_charlen_len __ARGS((char_u *str, int len));

src/proto/misc2.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ int decl __ARGS((pos_T *lp));
1414
linenr_T get_cursor_rel_lnum __ARGS((win_T *wp, linenr_T lnum));
1515
void check_cursor_lnum __ARGS((void));
1616
void check_cursor_col __ARGS((void));
17+
void check_cursor_col_win __ARGS((win_T *win));
1718
void check_cursor __ARGS((void));
1819
void adjust_cursor_col __ARGS((void));
1920
int leftcol_changed __ARGS((void));

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ static char *(features[]) =
709709

710710
static int included_patches[] =
711711
{ /* Add new patch number below this line */
712+
/**/
713+
239,
712714
/**/
713715
238,
714716
/**/

0 commit comments

Comments
 (0)