comparison src/misc2.c @ 25380:ac88cd21ae88 v8.2.3227

patch 8.2.3227: 'virtualedit' can only be set globally Commit: https://github.com/vim/vim/commit/53ba05b09075f14227f9be831a22ed16f7cc26b2 Author: Gary Johnson <garyjohn@spocom.com> Date: Mon Jul 26 22:19:10 2021 +0200 patch 8.2.3227: 'virtualedit' can only be set globally Problem: 'virtualedit' can only be set globally. Solution: Make 'virtualedit' global-local. (Gary Johnson, closes https://github.com/vim/vim/issues/8638)
author Bram Moolenaar <Bram@vim.org>
date Mon, 26 Jul 2021 22:30:05 +0200
parents dc66d0284518
children b80e4e9c4988
comparison
equal deleted inserted replaced
25379:549ff81ccdfe 25380:ac88cd21ae88
20 * Return TRUE if in the current mode we need to use virtual. 20 * Return TRUE if in the current mode we need to use virtual.
21 */ 21 */
22 int 22 int
23 virtual_active(void) 23 virtual_active(void)
24 { 24 {
25 unsigned int cur_ve_flags = get_ve_flags();
26
25 // While an operator is being executed we return "virtual_op", because 27 // While an operator is being executed we return "virtual_op", because
26 // VIsual_active has already been reset, thus we can't check for "block" 28 // VIsual_active has already been reset, thus we can't check for "block"
27 // being used. 29 // being used.
28 if (virtual_op != MAYBE) 30 if (virtual_op != MAYBE)
29 return virtual_op; 31 return virtual_op;
30 return (ve_flags == VE_ALL 32 return (cur_ve_flags == VE_ALL
31 || ((ve_flags & VE_BLOCK) && VIsual_active && VIsual_mode == Ctrl_V) 33 || ((cur_ve_flags & VE_BLOCK) && VIsual_active && VIsual_mode == Ctrl_V)
32 || ((ve_flags & VE_INSERT) && (State & INSERT))); 34 || ((cur_ve_flags & VE_INSERT) && (State & INSERT)));
33 } 35 }
34 36
35 /* 37 /*
36 * Get the screen position of the cursor. 38 * Get the screen position of the cursor.
37 */ 39 */
135 #endif 137 #endif
136 138
137 one_more = (State & INSERT) 139 one_more = (State & INSERT)
138 || restart_edit != NUL 140 || restart_edit != NUL
139 || (VIsual_active && *p_sel != 'o') 141 || (VIsual_active && *p_sel != 'o')
140 || ((ve_flags & VE_ONEMORE) && wcol < MAXCOL); 142 || ((get_ve_flags() & VE_ONEMORE) && wcol < MAXCOL);
141 line = ml_get_buf(curbuf, pos->lnum, FALSE); 143 line = ml_get_buf(curbuf, pos->lnum, FALSE);
142 144
143 if (wcol >= MAXCOL) 145 if (wcol >= MAXCOL)
144 { 146 {
145 idx = (int)STRLEN(line) - 1 + one_more; 147 idx = (int)STRLEN(line) - 1 + one_more;
547 * Make sure win->w_cursor.col is valid. 549 * Make sure win->w_cursor.col is valid.
548 */ 550 */
549 void 551 void
550 check_cursor_col_win(win_T *win) 552 check_cursor_col_win(win_T *win)
551 { 553 {
552 colnr_T len; 554 colnr_T len;
553 colnr_T oldcol = win->w_cursor.col; 555 colnr_T oldcol = win->w_cursor.col;
554 colnr_T oldcoladd = win->w_cursor.col + win->w_cursor.coladd; 556 colnr_T oldcoladd = win->w_cursor.col + win->w_cursor.coladd;
557 unsigned int cur_ve_flags = get_ve_flags();
555 558
556 len = (colnr_T)STRLEN(ml_get_buf(win->w_buffer, win->w_cursor.lnum, FALSE)); 559 len = (colnr_T)STRLEN(ml_get_buf(win->w_buffer, win->w_cursor.lnum, FALSE));
557 if (len == 0) 560 if (len == 0)
558 win->w_cursor.col = 0; 561 win->w_cursor.col = 0;
559 else if (win->w_cursor.col >= len) 562 else if (win->w_cursor.col >= len)
562 // - in Insert mode or restarting Insert mode 565 // - in Insert mode or restarting Insert mode
563 // - in Visual mode and 'selection' isn't "old" 566 // - in Visual mode and 'selection' isn't "old"
564 // - 'virtualedit' is set 567 // - 'virtualedit' is set
565 if ((State & INSERT) || restart_edit 568 if ((State & INSERT) || restart_edit
566 || (VIsual_active && *p_sel != 'o') 569 || (VIsual_active && *p_sel != 'o')
567 || (ve_flags & VE_ONEMORE) 570 || (cur_ve_flags & VE_ONEMORE)
568 || virtual_active()) 571 || virtual_active())
569 win->w_cursor.col = len; 572 win->w_cursor.col = len;
570 else 573 else
571 { 574 {
572 win->w_cursor.col = len - 1; 575 win->w_cursor.col = len - 1;
581 // If virtual editing is on, we can leave the cursor on the old position, 584 // If virtual editing is on, we can leave the cursor on the old position,
582 // only we must set it to virtual. But don't do it when at the end of the 585 // only we must set it to virtual. But don't do it when at the end of the
583 // line. 586 // line.
584 if (oldcol == MAXCOL) 587 if (oldcol == MAXCOL)
585 win->w_cursor.coladd = 0; 588 win->w_cursor.coladd = 0;
586 else if (ve_flags == VE_ALL) 589 else if (cur_ve_flags == VE_ALL)
587 { 590 {
588 if (oldcoladd > win->w_cursor.col) 591 if (oldcoladd > win->w_cursor.col)
589 { 592 {
590 win->w_cursor.coladd = oldcoladd - win->w_cursor.col; 593 win->w_cursor.coladd = oldcoladd - win->w_cursor.col;
591 594