Skip to content

Commit d79e550

Browse files
committed
patch 7.4.1087
Problem: CTRL-A and CTRL-X do not work properly with blockwise visual selection if there is a mix of Tab and spaces. Solution: Add OP_NR_ADD and OP_NR_SUB. (Hirohito Higashi)
1 parent 507edf6 commit d79e550

File tree

6 files changed

+487
-381
lines changed

6 files changed

+487
-381
lines changed

src/normal.c

Lines changed: 28 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ static void find_start_of_word __ARGS((pos_T *));
4040
static void find_end_of_word __ARGS((pos_T *));
4141
static int get_mouse_class __ARGS((char_u *p));
4242
#endif
43-
static void prep_redo_visual __ARGS((cmdarg_T *cap));
4443
static void prep_redo_cmd __ARGS((cmdarg_T *cap));
4544
static void prep_redo __ARGS((int regname, long, int, int, int, int, int));
4645
static int checkclearop __ARGS((oparg_T *oap));
@@ -1392,6 +1391,7 @@ do_pending_operator(cap, old_col, gui_yank)
13921391
static linenr_T redo_VIsual_line_count; /* number of lines */
13931392
static colnr_T redo_VIsual_vcol; /* number of cols or end column */
13941393
static long redo_VIsual_count; /* count for Visual operator */
1394+
static int redo_VIsual_arg; /* extra argument */
13951395
#ifdef FEAT_VIRTUALEDIT
13961396
int include_line_break = FALSE;
13971397
#endif
@@ -1699,6 +1699,7 @@ do_pending_operator(cap, old_col, gui_yank)
16991699
redo_VIsual_vcol = resel_VIsual_vcol;
17001700
redo_VIsual_line_count = resel_VIsual_line_count;
17011701
redo_VIsual_count = cap->count0;
1702+
redo_VIsual_arg = cap->arg;
17021703
}
17031704
}
17041705

@@ -2108,6 +2109,24 @@ do_pending_operator(cap, old_col, gui_yank)
21082109
oap->op_type == OP_FOLDDELREC, oap->is_VIsual);
21092110
break;
21102111
#endif
2112+
case OP_NR_ADD:
2113+
case OP_NR_SUB:
2114+
if (empty_region_error)
2115+
{
2116+
vim_beep(BO_OPER);
2117+
CancelRedo();
2118+
}
2119+
else
2120+
{
2121+
VIsual_active = TRUE;
2122+
#ifdef FEAT_LINEBREAK
2123+
curwin->w_p_lbr = lbr_saved;
2124+
#endif
2125+
op_addsub(oap, cap->count1, redo_VIsual_arg);
2126+
VIsual_active = FALSE;
2127+
}
2128+
check_cursor_col();
2129+
break;
21112130
default:
21122131
clearopbeep(oap);
21132132
}
@@ -3602,43 +3621,6 @@ find_ident_at_pos(wp, lnum, startcol, string, find_type)
36023621
return col;
36033622
}
36043623

3605-
/*
3606-
* Add commands to reselect Visual mode into the redo buffer.
3607-
*/
3608-
static void
3609-
prep_redo_visual(cap)
3610-
cmdarg_T *cap;
3611-
{
3612-
ResetRedobuff();
3613-
AppendCharToRedobuff(VIsual_mode);
3614-
if (VIsual_mode == 'V' && curbuf->b_visual.vi_end.lnum
3615-
!= curbuf->b_visual.vi_start.lnum)
3616-
{
3617-
AppendNumberToRedobuff(curbuf->b_visual.vi_end.lnum
3618-
- curbuf->b_visual.vi_start.lnum);
3619-
AppendCharToRedobuff('j');
3620-
}
3621-
else if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V)
3622-
{
3623-
/* block visual mode or char visual mmode*/
3624-
if (curbuf->b_visual.vi_end.lnum != curbuf->b_visual.vi_start.lnum)
3625-
{
3626-
AppendNumberToRedobuff(curbuf->b_visual.vi_end.lnum -
3627-
curbuf->b_visual.vi_start.lnum);
3628-
AppendCharToRedobuff('j');
3629-
}
3630-
if (curbuf->b_visual.vi_curswant == MAXCOL)
3631-
AppendCharToRedobuff('$');
3632-
else if (curbuf->b_visual.vi_end.col > curbuf->b_visual.vi_start.col)
3633-
{
3634-
AppendNumberToRedobuff(curbuf->b_visual.vi_end.col
3635-
- curbuf->b_visual.vi_start.col);
3636-
AppendCharToRedobuff(' ');
3637-
}
3638-
}
3639-
AppendNumberToRedobuff(cap->count1);
3640-
}
3641-
36423624
/*
36433625
* Prepare for redo of a normal command.
36443626
*/
@@ -4243,30 +4225,16 @@ nv_help(cap)
42434225
nv_addsub(cap)
42444226
cmdarg_T *cap;
42454227
{
4246-
int visual = VIsual_active;
4247-
4248-
if (cap->oap->op_type == OP_NOP
4249-
&& do_addsub((int)cap->cmdchar, cap->count1, cap->arg) == OK)
4228+
if (!VIsual_active && cap->oap->op_type == OP_NOP)
42504229
{
4251-
if (visual)
4252-
{
4253-
prep_redo_visual(cap);
4254-
if (cap->arg)
4255-
AppendCharToRedobuff('g');
4256-
AppendCharToRedobuff(cap->cmdchar);
4257-
}
4258-
else
4259-
prep_redo_cmd(cap);
4230+
cap->oap->op_type = cap->cmdchar == Ctrl_A ? OP_NR_ADD : OP_NR_SUB;
4231+
op_addsub(cap->oap, cap->count1, cap->arg);
4232+
cap->oap->op_type = OP_NOP;
42604233
}
4234+
else if (VIsual_active)
4235+
nv_operator(cap);
42614236
else
4262-
clearopbeep(cap->oap);
4263-
if (visual)
4264-
{
4265-
VIsual_active = FALSE;
4266-
redo_VIsual_busy = FALSE;
4267-
may_clear_cmdline();
4268-
redraw_later(INVERTED);
4269-
}
4237+
clearop(cap->oap);
42704238
}
42714239

42724240
/*
@@ -7924,6 +7892,7 @@ nv_g_cmd(cap)
79247892
{
79257893
cap->arg = TRUE;
79267894
cap->cmdchar = cap->nchar;
7895+
cap->nchar = NUL;
79277896
nv_addsub(cap);
79287897
}
79297898
else

0 commit comments

Comments
 (0)