mirror of
https://github.com/neovim/neovim.git
synced 2024-12-29 14:41:06 -07:00
Merge pull request #17166 from Shougo/vim-8.2.4160
vim-patch:8.2.4160: cannot change the register used for Select mode d…
This commit is contained in:
commit
9c4e617064
@ -478,6 +478,10 @@ Commands in Select mode:
|
||||
- ESC stops Select mode.
|
||||
- CTRL-O switches to Visual mode for the duration of one command. *v_CTRL-O*
|
||||
- CTRL-G switches to Visual mode.
|
||||
- CTRL-R {register} selects the register to be used for the text that is
|
||||
deleted when typing text. *v_CTRL-R*
|
||||
Unless you specify the "_" (black hole) register, the unnamed register is
|
||||
also overwritten.
|
||||
|
||||
Otherwise, typed characters are handled as in Visual mode.
|
||||
|
||||
|
@ -524,6 +524,8 @@ EXTERN pos_T VIsual;
|
||||
EXTERN int VIsual_active INIT(= false);
|
||||
/// Whether Select mode is active.
|
||||
EXTERN int VIsual_select INIT(= false);
|
||||
/// Register name for Select mode
|
||||
EXTERN int VIsual_select_reg INIT(= 0);
|
||||
/// Restart Select mode when next cmd finished
|
||||
EXTERN int restart_VIsual_select INIT(= 0);
|
||||
/// Whether to restart the selection after a Select-mode mapping or menu.
|
||||
|
@ -164,7 +164,7 @@ static const struct nv_cmd {
|
||||
{ Ctrl_O, nv_ctrlo, 0, 0 },
|
||||
{ Ctrl_P, nv_up, NV_STS, false },
|
||||
{ Ctrl_Q, nv_visual, 0, false },
|
||||
{ Ctrl_R, nv_redo, 0, 0 },
|
||||
{ Ctrl_R, nv_redo_or_register, 0, 0 },
|
||||
{ Ctrl_S, nv_ignore, 0, 0 },
|
||||
{ Ctrl_T, nv_tagpop, NV_NCW, 0 },
|
||||
{ Ctrl_U, nv_halfpage, 0, 0 },
|
||||
@ -961,6 +961,7 @@ normal_end:
|
||||
&& s->oa.regname == 0) {
|
||||
if (restart_VIsual_select == 1) {
|
||||
VIsual_select = true;
|
||||
VIsual_select_reg = 0;
|
||||
trigger_modechanged();
|
||||
showmode();
|
||||
restart_VIsual_select = 0;
|
||||
@ -6195,6 +6196,7 @@ static void nv_g_cmd(cmdarg_T *cap)
|
||||
// start Select mode.
|
||||
if (cap->arg) {
|
||||
VIsual_select = true;
|
||||
VIsual_select_reg = 0;
|
||||
} else {
|
||||
may_start_select('c');
|
||||
}
|
||||
@ -6707,11 +6709,26 @@ static void nv_dot(cmdarg_T *cap)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* CTRL-R: undo undo
|
||||
*/
|
||||
static void nv_redo(cmdarg_T *cap)
|
||||
// CTRL-R: undo undo or specify register in select mode
|
||||
static void nv_redo_or_register(cmdarg_T *cap)
|
||||
{
|
||||
if (VIsual_select && VIsual_active) {
|
||||
int reg;
|
||||
// Get register name
|
||||
no_mapping++;
|
||||
reg = plain_vgetc();
|
||||
LANGMAP_ADJUST(reg, true);
|
||||
no_mapping--;
|
||||
|
||||
if (reg == '"') {
|
||||
// the unnamed register is 0
|
||||
reg = 0;
|
||||
}
|
||||
|
||||
VIsual_select_reg = valid_yank_reg(reg, true) ? reg : 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!checkclearopq(cap->oap)) {
|
||||
u_redo((int)cap->count1);
|
||||
curwin->w_set_curswant = true;
|
||||
@ -7032,6 +7049,7 @@ static void nv_select(cmdarg_T *cap)
|
||||
{
|
||||
if (VIsual_active) {
|
||||
VIsual_select = true;
|
||||
VIsual_select_reg = 0;
|
||||
} else if (VIsual_reselect) {
|
||||
cap->nchar = 'v'; // fake "gv" command
|
||||
cap->arg = true;
|
||||
|
@ -1435,6 +1435,11 @@ int op_delete(oparg_T *oap)
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (VIsual_select && oap->is_VIsual) {
|
||||
// Use the register given with CTRL_R, defaults to zero
|
||||
oap->regname = VIsual_select_reg;
|
||||
}
|
||||
|
||||
mb_adjust_opend(oap);
|
||||
|
||||
/*
|
||||
|
57
src/nvim/testdir/test_selectmode.vim
Normal file
57
src/nvim/testdir/test_selectmode.vim
Normal file
@ -0,0 +1,57 @@
|
||||
" Test for Select-mode
|
||||
|
||||
source shared.vim
|
||||
|
||||
" Test for selecting a register with CTRL-R
|
||||
func Test_selectmode_register()
|
||||
new
|
||||
|
||||
" Default behavior: use unnamed register
|
||||
call setline(1, 'foo')
|
||||
call setreg('"', 'bar')
|
||||
call setreg('a', 'baz')
|
||||
exe ":norm! v\<c-g>a"
|
||||
call assert_equal(getline('.'), 'aoo')
|
||||
call assert_equal('f', getreg('"'))
|
||||
call assert_equal('baz', getreg('a'))
|
||||
|
||||
" Use the black hole register
|
||||
call setline(1, 'foo')
|
||||
call setreg('"', 'bar')
|
||||
call setreg('a', 'baz')
|
||||
exe ":norm! v\<c-g>\<c-r>_a"
|
||||
call assert_equal(getline('.'), 'aoo')
|
||||
call assert_equal('bar', getreg('"'))
|
||||
call assert_equal('baz', getreg('a'))
|
||||
|
||||
" Invalid register: use unnamed register
|
||||
call setline(1, 'foo')
|
||||
call setreg('"', 'bar')
|
||||
call setreg('a', 'baz')
|
||||
exe ":norm! v\<c-g>\<c-r>?a"
|
||||
call assert_equal(getline('.'), 'aoo')
|
||||
call assert_equal('f', getreg('"'))
|
||||
call assert_equal('baz', getreg('a'))
|
||||
|
||||
" Use unnamed register
|
||||
call setline(1, 'foo')
|
||||
call setreg('"', 'bar')
|
||||
call setreg('a', 'baz')
|
||||
exe ":norm! v\<c-g>\<c-r>\"a"
|
||||
call assert_equal(getline('.'), 'aoo')
|
||||
call assert_equal('f', getreg('"'))
|
||||
call assert_equal('baz', getreg('a'))
|
||||
|
||||
" use specicifed register, unnamed register is also written
|
||||
call setline(1, 'foo')
|
||||
call setreg('"', 'bar')
|
||||
call setreg('a', 'baz')
|
||||
exe ":norm! v\<c-g>\<c-r>aa"
|
||||
call assert_equal(getline('.'), 'aoo')
|
||||
call assert_equal('f', getreg('"'))
|
||||
call assert_equal('f', getreg('a'))
|
||||
|
||||
bw!
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
Loading…
Reference in New Issue
Block a user