Skip to content

Commit 03c3bd9

Browse files
committed
patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Problem: Block Visual mode operators not correct when 'linebreak' set. Solution: Set w_p_lbr to lbr_saved more often. (Ken Takata, closes #5524)
1 parent dfede9a commit 03c3bd9

3 files changed

Lines changed: 44 additions & 15 deletions

File tree

src/ops.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,7 +2744,12 @@ block_prep(
27442744
char_u *line;
27452745
char_u *prev_pstart;
27462746
char_u *prev_pend;
2747+
#ifdef FEAT_LINEBREAK
2748+
int lbr_saved = curwin->w_p_lbr;
27472749

2750+
// Avoid a problem with unwanted linebreaks in block mode.
2751+
curwin->w_p_lbr = FALSE;
2752+
#endif
27482753
bdp->startspaces = 0;
27492754
bdp->endspaces = 0;
27502755
bdp->textlen = 0;
@@ -2863,6 +2868,9 @@ block_prep(
28632868
}
28642869
bdp->textcol = (colnr_T) (pstart - line);
28652870
bdp->textstart = pstart;
2871+
#ifdef FEAT_LINEBREAK
2872+
curwin->w_p_lbr = lbr_saved;
2873+
#endif
28662874
}
28672875

28682876
/*
@@ -4556,11 +4564,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
45564564
#ifdef FEAT_LINEBREAK
45574565
// Restore linebreak, so that when the user edits it looks as
45584566
// before.
4559-
if (curwin->w_p_lbr != lbr_saved)
4560-
{
4561-
curwin->w_p_lbr = lbr_saved;
4562-
get_op_vcol(oap, redo_VIsual_mode, FALSE);
4563-
}
4567+
curwin->w_p_lbr = lbr_saved;
45644568
#endif
45654569
// Reset finish_op now, don't want it set inside edit().
45664570
finish_op = FALSE;
@@ -4663,11 +4667,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
46634667
#ifdef FEAT_LINEBREAK
46644668
// Restore linebreak, so that when the user edits it looks as
46654669
// before.
4666-
if (curwin->w_p_lbr != lbr_saved)
4667-
{
4668-
curwin->w_p_lbr = lbr_saved;
4669-
get_op_vcol(oap, redo_VIsual_mode, FALSE);
4670-
}
4670+
curwin->w_p_lbr = lbr_saved;
46714671
#endif
46724672
op_insert(oap, cap->count1);
46734673
#ifdef FEAT_LINEBREAK
@@ -4698,11 +4698,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
46984698
#ifdef FEAT_LINEBREAK
46994699
// Restore linebreak, so that when the user edits it looks as
47004700
// before.
4701-
if (curwin->w_p_lbr != lbr_saved)
4702-
{
4703-
curwin->w_p_lbr = lbr_saved;
4704-
get_op_vcol(oap, redo_VIsual_mode, FALSE);
4705-
}
4701+
curwin->w_p_lbr = lbr_saved;
47064702
#endif
47074703
op_replace(oap, cap->nchar);
47084704
}

src/testdir/test_listlbr.vim

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,37 @@ func Test_linebreak_with_conceal()
100100
call s:close_windows()
101101
endfunc
102102

103+
func Test_linebreak_with_visual_operations()
104+
call s:test_windows()
105+
let line = '1234567890 2234567890 3234567890'
106+
call setline(1, line)
107+
108+
" yank
109+
exec "norm! ^w\<C-V>ey"
110+
call assert_equal('2234567890', @@)
111+
exec "norm! w\<C-V>ey"
112+
call assert_equal('3234567890', @@)
113+
114+
" increment / decrement
115+
exec "norm! ^w\<C-V>\<C-A>w\<C-V>\<C-X>"
116+
call assert_equal('1234567890 3234567890 2234567890', getline(1))
117+
118+
" replace
119+
exec "norm! ^w\<C-V>3lraw\<C-V>3lrb"
120+
call assert_equal('1234567890 aaaa567890 bbbb567890', getline(1))
121+
122+
" tilde
123+
exec "norm! ^w\<C-V>2l~w\<C-V>2l~"
124+
call assert_equal('1234567890 AAAa567890 BBBb567890', getline(1))
125+
126+
" delete and insert
127+
exec "norm! ^w\<C-V>3lc2345\<Esc>w\<C-V>3lc3456\<Esc>"
128+
call assert_equal('1234567890 2345567890 3456567890', getline(1))
129+
call assert_equal('BBBb', @@)
130+
131+
call s:close_windows()
132+
endfunc
133+
103134
func Test_virtual_block()
104135
call s:test_windows('setl sbr=+')
105136
call setline(1, [

src/version.c

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

743743
static int included_patches[] =
744744
{ /* Add new patch number below this line */
745+
/**/
746+
147,
745747
/**/
746748
146,
747749
/**/

0 commit comments

Comments
 (0)