vim-patch:9.1.0683: mode() returns wrong value with <Cmd> mapping (#30109)

Problem:  mode() returns wrong value with <Cmd> mapping
Solution: Change decision priority of VIsual_active and move
          visual mode a bit further down (kuuote)

closes: vim/vim#15533

0fd1cb1b1f

Co-authored-by: kuuote <znmxodq1@gmail.com>
This commit is contained in:
zeertzjq 2024-08-22 05:30:21 +08:00 committed by GitHub
parent 4e5607eb37
commit 362389eb15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 13 deletions

View File

@ -177,17 +177,8 @@ void get_mode(char *buf)
{ {
int i = 0; int i = 0;
if (VIsual_active) { if (State == MODE_HITRETURN || State == MODE_ASKMORE
if (VIsual_select) { || State == MODE_SETWSIZE || State == MODE_CONFIRM) {
buf[i++] = (char)(VIsual_mode + 's' - 'v');
} else {
buf[i++] = (char)VIsual_mode;
if (restart_VIsual_select) {
buf[i++] = 's';
}
}
} else if (State == MODE_HITRETURN || State == MODE_ASKMORE || State == MODE_SETWSIZE
|| State == MODE_CONFIRM) {
buf[i++] = 'r'; buf[i++] = 'r';
if (State == MODE_ASKMORE) { if (State == MODE_ASKMORE) {
buf[i++] = 'm'; buf[i++] = 'm';
@ -222,6 +213,15 @@ void get_mode(char *buf)
} }
} else if (State & MODE_TERMINAL) { } else if (State & MODE_TERMINAL) {
buf[i++] = 't'; buf[i++] = 't';
} else if (VIsual_active) {
if (VIsual_select) {
buf[i++] = (char)(VIsual_mode + 's' - 'v');
} else {
buf[i++] = (char)VIsual_mode;
if (restart_VIsual_select) {
buf[i++] = 's';
}
}
} else { } else {
buf[i++] = 'n'; buf[i++] = 'n';
if (finish_op) { if (finish_op) {
@ -233,8 +233,7 @@ void get_mode(char *buf)
if (restart_edit == 'I') { if (restart_edit == 'I') {
buf[i++] = 'T'; buf[i++] = 'T';
} }
} else if (restart_edit == 'I' || restart_edit == 'R' } else if (restart_edit == 'I' || restart_edit == 'R' || restart_edit == 'V') {
|| restart_edit == 'V') {
buf[i++] = 'i'; buf[i++] = 'i';
buf[i++] = (char)restart_edit; buf[i++] = (char)restart_edit;
} }

View File

@ -810,6 +810,10 @@ func Test_mode()
call feedkeys("gQ\<Insert>\<F2>vi\<CR>", 'xt') call feedkeys("gQ\<Insert>\<F2>vi\<CR>", 'xt')
call assert_equal("c-cvr", g:current_modes) call assert_equal("c-cvr", g:current_modes)
" Commandline mode in Visual mode should return "c-c", never "v-v".
call feedkeys("v\<Cmd>call input('')\<CR>\<F2>\<CR>\<Esc>", 'xt')
call assert_equal("c-c", g:current_modes)
" Executing commands in Vim Ex mode should return "cv", never "cvr", " Executing commands in Vim Ex mode should return "cv", never "cvr",
" as Cmdline editing has already ended. " as Cmdline editing has already ended.
call feedkeys("gQcall Save_mode()\<CR>vi\<CR>", 'xt') call feedkeys("gQcall Save_mode()\<CR>vi\<CR>", 'xt')