void
end_visual_mode(void)
{
+ VIsual_select_exclu_adj = FALSE;
end_visual_mode_keep_button();
reset_held_button();
}
nv_csearch(cmdarg_T *cap)
{
int t_cmd;
+ int cursor_dec = FALSE;
+
+ // If adjusted cursor position previously, unadjust it.
+ if (*p_sel == 'e' && VIsual_active && VIsual_mode == 'v'
+ && VIsual_select_exclu_adj)
+ {
+ unadjust_for_sel();
+ cursor_dec = TRUE;
+ }
if (cap->cmdchar == 't' || cap->cmdchar == 'T')
t_cmd = TRUE;
if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL)
{
clearopbeep(cap->oap);
+ // Revert unadjust when failed.
+ if (cursor_dec)
+ adjust_for_sel(cap);
return;
}
n_start_visual_mode(cap->cmdchar);
if (VIsual_mode != 'V' && *p_sel == 'e')
++cap->count1; // include one more char
+ else
+ VIsual_select_exclu_adj = FALSE;
if (cap->count0 > 0 && --cap->count1 > 0)
{
// With a count select that many characters or lines.
else
++curwin->w_cursor.col;
cap->oap->inclusive = FALSE;
+ VIsual_select_exclu_adj = TRUE;
}
}
unadjust_for_sel_inner(pos_T *pp)
{
colnr_T cs, ce;
+ VIsual_select_exclu_adj = FALSE;
if (pp->coladd > 0)
--pp->coladd;
bw!
endfunc
+" Test for inclusive motion in visual mode with 'exclusive' selection
+func Test_inclusive_motion_selection_exclusive()
+ func s:compare_exclu_inclu(line, keys, expected_exclu)
+ let msg = "data: '" . a:line . "' operation: '" . a:keys . "'"
+ call setline(1, a:line)
+ set selection=exclusive
+ call feedkeys(a:keys, 'xt')
+ call assert_equal(a:expected_exclu, getpos('.'), msg)
+ let pos_ex = col('.')
+ set selection=inclusive
+ call feedkeys(a:keys, 'xt')
+ let pos_in = col('.')
+ call assert_equal(1, pos_ex - pos_in, msg)
+ endfunc
+
+ new
+ " Test 'e' motion
+ set selection=exclusive
+ call setline(1, 'eins zwei drei')
+ norm! ggvey
+ call assert_equal('eins', @")
+ call setline(1, 'abc(abc)abc')
+ norm! ggveeed
+ call assert_equal(')abc', getline(1))
+ call setline(1, 'abc(abc)abc')
+ norm! gg3lvey
+ call assert_equal('(abc', @")
+ call s:compare_exclu_inclu('abc(abc)abc', 'ggveee', [0, 1, 8, 0])
+ " Test 'f' motion
+ call s:compare_exclu_inclu('geschwindigkeit', 'ggvfefe', [0, 1, 14, 0])
+ call s:compare_exclu_inclu('loooooooooooong', 'ggv2fo2fo2fo', [0, 1, 8, 0])
+ " Test 't' motion
+ call s:compare_exclu_inclu('geschwindigkeit', 'ggv2te', [0, 1, 13, 0])
+ call s:compare_exclu_inclu('loooooooooooong', 'gglv2to2to2to', [0, 1, 6, 0])
+ " Test ';' motion
+ call s:compare_exclu_inclu('geschwindigkeit', 'ggvfi;;', [0, 1, 15, 0])
+ call s:compare_exclu_inclu('geschwindigkeit', 'ggvti;;', [0, 1, 14, 0])
+ call s:compare_exclu_inclu('loooooooooooong', 'ggv2fo;;', [0, 1, 6, 0])
+ call s:compare_exclu_inclu('loooooooooooong', 'ggvl2to;;', [0, 1, 6, 0])
+ " Clean up
+ set selection&
+ bw!
+endfunc
+
" Test for starting linewise visual with a count.
" This test needs to be run without any previous visual mode. Otherwise the
" count will use the count from the previous visual mode.