mirror of
https://github.com/vim/vim
synced 2025-07-15 16:51:57 +00:00
patch 9.0.0697: cursor in wrong position with Visual substitute
Problem: Cursor in wrong position with Visual substitute. Solution: When restoring 'linebreak' mark the virtual column as invalid. (closes #11309, closes #11311)
This commit is contained in:
64
src/ops.c
64
src/ops.c
@ -2207,6 +2207,35 @@ theend:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reset 'linebreak' and take care of side effects.
|
||||||
|
* Returns the previous value, to be passed to restore_lbr().
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
reset_lbr(void)
|
||||||
|
{
|
||||||
|
if (!curwin->w_p_lbr)
|
||||||
|
return FALSE;
|
||||||
|
// changing 'linebreak' may require w_virtcol to be updated
|
||||||
|
curwin->w_p_lbr = FALSE;
|
||||||
|
curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Restore 'linebreak' and take care of side effects.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
restore_lbr(int lbr_saved)
|
||||||
|
{
|
||||||
|
if (!curwin->w_p_lbr && lbr_saved)
|
||||||
|
{
|
||||||
|
// changing 'linebreak' may require w_virtcol to be updated
|
||||||
|
curwin->w_p_lbr = TRUE;
|
||||||
|
curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* prepare a few things for block mode yank/delete/tilde
|
* prepare a few things for block mode yank/delete/tilde
|
||||||
*
|
*
|
||||||
@ -2235,11 +2264,10 @@ block_prep(
|
|||||||
char_u *prev_pend;
|
char_u *prev_pend;
|
||||||
chartabsize_T cts;
|
chartabsize_T cts;
|
||||||
#ifdef FEAT_LINEBREAK
|
#ifdef FEAT_LINEBREAK
|
||||||
int lbr_saved = curwin->w_p_lbr;
|
// Avoid a problem with unwanted linebreaks in block mode.
|
||||||
|
int lbr_saved = reset_lbr();
|
||||||
// Avoid a problem with unwanted linebreaks in block mode.
|
|
||||||
curwin->w_p_lbr = FALSE;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bdp->startspaces = 0;
|
bdp->startspaces = 0;
|
||||||
bdp->endspaces = 0;
|
bdp->endspaces = 0;
|
||||||
bdp->textlen = 0;
|
bdp->textlen = 0;
|
||||||
@ -2369,7 +2397,7 @@ block_prep(
|
|||||||
bdp->textcol = (colnr_T) (pstart - line);
|
bdp->textcol = (colnr_T) (pstart - line);
|
||||||
bdp->textstart = pstart;
|
bdp->textstart = pstart;
|
||||||
#ifdef FEAT_LINEBREAK
|
#ifdef FEAT_LINEBREAK
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3570,9 +3598,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
|
|||||||
|
|
||||||
#ifdef FEAT_LINEBREAK
|
#ifdef FEAT_LINEBREAK
|
||||||
// Avoid a problem with unwanted linebreaks in block mode.
|
// Avoid a problem with unwanted linebreaks in block mode.
|
||||||
if (curwin->w_p_lbr)
|
(void)reset_lbr();
|
||||||
curwin->w_valid &= ~VALID_VIRTCOL;
|
|
||||||
curwin->w_p_lbr = FALSE;
|
|
||||||
#endif
|
#endif
|
||||||
oap->is_VIsual = VIsual_active;
|
oap->is_VIsual = VIsual_active;
|
||||||
if (oap->motion_force == 'V')
|
if (oap->motion_force == 'V')
|
||||||
@ -3908,7 +3934,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
|
|||||||
{
|
{
|
||||||
#ifdef FEAT_LINEBREAK
|
#ifdef FEAT_LINEBREAK
|
||||||
// make sure redrawing is correct
|
// make sure redrawing is correct
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
#endif
|
#endif
|
||||||
redraw_curbuf_later(UPD_INVERTED);
|
redraw_curbuf_later(UPD_INVERTED);
|
||||||
}
|
}
|
||||||
@ -3948,7 +3974,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
|
|||||||
))
|
))
|
||||||
{
|
{
|
||||||
#ifdef FEAT_LINEBREAK
|
#ifdef FEAT_LINEBREAK
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
#endif
|
#endif
|
||||||
redraw_curbuf_later(UPD_INVERTED);
|
redraw_curbuf_later(UPD_INVERTED);
|
||||||
}
|
}
|
||||||
@ -4036,7 +4062,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef FEAT_LINEBREAK
|
#ifdef FEAT_LINEBREAK
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
#endif
|
#endif
|
||||||
oap->excl_tr_ws = cap->cmdchar == 'z';
|
oap->excl_tr_ws = cap->cmdchar == 'z';
|
||||||
(void)op_yank(oap, FALSE, !gui_yank);
|
(void)op_yank(oap, FALSE, !gui_yank);
|
||||||
@ -4065,7 +4091,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
|
|||||||
#ifdef FEAT_LINEBREAK
|
#ifdef FEAT_LINEBREAK
|
||||||
// Restore linebreak, so that when the user edits it looks as
|
// Restore linebreak, so that when the user edits it looks as
|
||||||
// before.
|
// before.
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
#endif
|
#endif
|
||||||
// Reset finish_op now, don't want it set inside edit().
|
// Reset finish_op now, don't want it set inside edit().
|
||||||
finish_op = FALSE;
|
finish_op = FALSE;
|
||||||
@ -4143,7 +4169,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
|
|||||||
#ifdef FEAT_LINEBREAK
|
#ifdef FEAT_LINEBREAK
|
||||||
// Restore linebreak, so that when the user edits it looks as
|
// Restore linebreak, so that when the user edits it looks as
|
||||||
// before.
|
// before.
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
#endif
|
#endif
|
||||||
// call 'operatorfunc'
|
// call 'operatorfunc'
|
||||||
op_function(oap);
|
op_function(oap);
|
||||||
@ -4172,12 +4198,12 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
|
|||||||
#ifdef FEAT_LINEBREAK
|
#ifdef FEAT_LINEBREAK
|
||||||
// Restore linebreak, so that when the user edits it looks as
|
// Restore linebreak, so that when the user edits it looks as
|
||||||
// before.
|
// before.
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
#endif
|
#endif
|
||||||
op_insert(oap, cap->count1);
|
op_insert(oap, cap->count1);
|
||||||
#ifdef FEAT_LINEBREAK
|
#ifdef FEAT_LINEBREAK
|
||||||
// Reset linebreak, so that formatting works correctly.
|
// Reset linebreak, so that formatting works correctly.
|
||||||
curwin->w_p_lbr = FALSE;
|
(void)reset_lbr();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO: when inserting in several lines, should format all
|
// TODO: when inserting in several lines, should format all
|
||||||
@ -4203,7 +4229,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
|
|||||||
#ifdef FEAT_LINEBREAK
|
#ifdef FEAT_LINEBREAK
|
||||||
// Restore linebreak, so that when the user edits it looks as
|
// Restore linebreak, so that when the user edits it looks as
|
||||||
// before.
|
// before.
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
#endif
|
#endif
|
||||||
op_replace(oap, cap->nchar);
|
op_replace(oap, cap->nchar);
|
||||||
}
|
}
|
||||||
@ -4246,7 +4272,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
|
|||||||
{
|
{
|
||||||
VIsual_active = TRUE;
|
VIsual_active = TRUE;
|
||||||
#ifdef FEAT_LINEBREAK
|
#ifdef FEAT_LINEBREAK
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
#endif
|
#endif
|
||||||
op_addsub(oap, cap->count1, redo_VIsual.rv_arg);
|
op_addsub(oap, cap->count1, redo_VIsual.rv_arg);
|
||||||
VIsual_active = FALSE;
|
VIsual_active = FALSE;
|
||||||
@ -4265,7 +4291,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
|
|||||||
|| oap->op_type == OP_DELETE))
|
|| oap->op_type == OP_DELETE))
|
||||||
{
|
{
|
||||||
#ifdef FEAT_LINEBREAK
|
#ifdef FEAT_LINEBREAK
|
||||||
curwin->w_p_lbr = FALSE;
|
(void)reset_lbr();
|
||||||
#endif
|
#endif
|
||||||
coladvance(curwin->w_curswant = old_col);
|
coladvance(curwin->w_curswant = old_col);
|
||||||
}
|
}
|
||||||
@ -4279,6 +4305,6 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
|
|||||||
motion_force = NUL;
|
motion_force = NUL;
|
||||||
}
|
}
|
||||||
#ifdef FEAT_LINEBREAK
|
#ifdef FEAT_LINEBREAK
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
8
src/testdir/dumps/Test_linebreak_reset_restore_1.dump
Normal file
8
src/testdir/dumps/Test_linebreak_reset_restore_1.dump
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|a+0&#ffffff0@64| @9
|
||||||
|
|b@9| > @63
|
||||||
|
|~+0#4040ff13&| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
| +0#0000000&@56|1|,|7|8|-|8|7| @6|A|l@1|
|
@ -8,6 +8,7 @@ CheckOption linebreak
|
|||||||
CheckFeature conceal
|
CheckFeature conceal
|
||||||
|
|
||||||
source view_util.vim
|
source view_util.vim
|
||||||
|
source screendump.vim
|
||||||
|
|
||||||
function s:screen_lines(lnum, width) abort
|
function s:screen_lines(lnum, width) abort
|
||||||
return ScreenLines(a:lnum, a:width)
|
return ScreenLines(a:lnum, a:width)
|
||||||
@ -133,6 +134,26 @@ func Test_linebreak_with_visual_operations()
|
|||||||
call s:close_windows()
|
call s:close_windows()
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_linebreak_reset_restore()
|
||||||
|
CheckScreendump
|
||||||
|
|
||||||
|
let lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
&linebreak = true
|
||||||
|
&showcmd = true
|
||||||
|
&showmode = false
|
||||||
|
('a'->repeat(&columns - 10) .. ' ' .. 'b'->repeat(10) .. ' c')->setline(1)
|
||||||
|
END
|
||||||
|
call writefile(lines, 'XlbrResetRestore', 'D')
|
||||||
|
let buf = RunVimInTerminal('-S XlbrResetRestore', {'rows': 8})
|
||||||
|
|
||||||
|
call term_sendkeys(buf, '$v$s')
|
||||||
|
call VerifyScreenDump(buf, 'Test_linebreak_reset_restore_1', {})
|
||||||
|
|
||||||
|
call term_sendkeys(buf, "\<Esc>")
|
||||||
|
call StopVimInTerminal(buf)
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_virtual_block()
|
func Test_virtual_block()
|
||||||
call s:test_windows('setl sbr=+')
|
call s:test_windows('setl sbr=+')
|
||||||
call setline(1, [
|
call setline(1, [
|
||||||
|
@ -1501,5 +1501,37 @@ func Test_switch_buffer_ends_visual_mode()
|
|||||||
exe 'bwipe!' buf2
|
exe 'bwipe!' buf2
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Test that cursor is drawn at correct position after an operator in Visual
|
||||||
|
" mode when 'linebreak' and 'showcmd' are enabled.
|
||||||
|
func Test_visual_operator_with_linebreak()
|
||||||
|
CheckRunVimInTerminal
|
||||||
|
|
||||||
|
let lines =<< trim END
|
||||||
|
set linebreak showcmd noshowmode
|
||||||
|
call setline(1, repeat('a', &columns - 10) .. ' bbbbbbbbbb c')
|
||||||
|
END
|
||||||
|
call writefile(lines, 'XTest_visual_op_linebreak', 'D')
|
||||||
|
|
||||||
|
let buf = RunVimInTerminal('-S XTest_visual_op_linebreak', {'rows': 6})
|
||||||
|
|
||||||
|
call term_sendkeys(buf, '$v$')
|
||||||
|
call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])})
|
||||||
|
call term_sendkeys(buf, 'zo')
|
||||||
|
call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])})
|
||||||
|
|
||||||
|
call term_sendkeys(buf, "$\<C-V>$")
|
||||||
|
call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])})
|
||||||
|
call term_sendkeys(buf, 'I')
|
||||||
|
call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])})
|
||||||
|
|
||||||
|
call term_sendkeys(buf, "\<Esc>$v$")
|
||||||
|
call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])})
|
||||||
|
call term_sendkeys(buf, 's')
|
||||||
|
call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])})
|
||||||
|
|
||||||
|
" clean up
|
||||||
|
call term_sendkeys(buf, "\<Esc>")
|
||||||
|
call StopVimInTerminal(buf)
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@ -699,6 +699,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
697,
|
||||||
/**/
|
/**/
|
||||||
696,
|
696,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user