From 540ed646358f9e3910681add39aa96a937074668 Mon Sep 17 00:00:00 2001 From: ckelsel Date: Sun, 19 Nov 2017 19:15:03 +0800 Subject: vim-patch:8.0.0283 Problem: The return value of mode() does not indicate that completion is active in Replace and Insert mode. (Zhen-Huan (Kenny) Hu) Solution: Add "c" or "x" for two kinds of completion. (Yegappan Lakshmanan, closes vim/vim#1397) Test some more modes. https://github.com/vim/vim/commit/e90858d0229444b3cd16b1cd3a8d61a24c435705 --- src/nvim/state.c | 24 +++++++---- src/nvim/testdir/test_functions.vim | 85 +++++++++++++++++++++++++++++++++++++ src/nvim/testdir/test_mapping.vim | 4 +- src/nvim/version.c | 2 +- 4 files changed, 105 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/nvim/state.c b/src/nvim/state.c index 4d9032b7a5..44a4de8abb 100644 --- a/src/nvim/state.c +++ b/src/nvim/state.c @@ -14,6 +14,8 @@ #include "nvim/option_defs.h" #include "nvim/ui.h" #include "nvim/os/input.h" +#include "nvim/ex_docmd.h" +#include "nvim/edit.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "state.c.generated.h" @@ -127,19 +129,25 @@ char *get_mode(void) if (State & VREPLACE_FLAG) { buf[0] = 'R'; buf[1] = 'v'; - } else if (State & REPLACE_FLAG) { - buf[0] = 'R'; } else { - buf[0] = 'i'; + if (State & REPLACE_FLAG) { + buf[0] = 'R'; + } else { + buf[0] = 'i'; + } + if (ins_compl_active()) { + buf[1] = 'c'; + } else if (ctrl_x_mode == 1) { + buf[1] = 'x'; + } } - } else if (State & CMDLINE) { + } else if (State & CMDLINE || exmode_active) { buf[0] = 'c'; - if (exmode_active) { + if (exmode_active == EXMODE_VIM) { buf[1] = 'v'; + } else if (exmode_active == EXMODE_NORMAL) { + buf[1] = 'e'; } - } else if (exmode_active) { - buf[0] = 'c'; - buf[1] = 'e'; } else if (State & TERM_FOCUS) { buf[0] = 't'; } else { diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 237a2dc820..59807ca946 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -191,4 +191,89 @@ func Test_toupper() call assert_equal("ⱥ ⱦ", tolower("Ⱥ Ⱦ")) endfunc +" Tests for the mode() function +let current_modes = '' +func! Save_mode() + let g:current_modes = mode(0) . '-' . mode(1) + return '' +endfunc + +func! Test_mode() + new + call append(0, ["Blue Ball Black", "Brown Band Bowl", ""]) + + inoremap =Save_mode() + + normal! 3G + exe "normal i\\" + call assert_equal('i-i', g:current_modes) + exe "normal i\uBa\\\u" + call assert_equal('i-ic', g:current_modes) + exe "normal iBro\\\u" + call assert_equal('i-ic', g:current_modes) + exe "normal iBa\\\u" + call assert_equal('i-ix', g:current_modes) + exe "normal iBa\\\\u" + call assert_equal('i-ic', g:current_modes) + exe "normal iBro\\\\u" + call assert_equal('i-ic', g:current_modes) + exe "normal iBro\\\\\u" + call assert_equal('i-ic', g:current_modes) + exe "normal iCom\\\u" + call assert_equal('i-ic', g:current_modes) + exe "normal iCom\\\\u" + call assert_equal('i-ic', g:current_modes) + + exe "normal RBa\\\u" + call assert_equal('R-Rc', g:current_modes) + exe "normal RBro\\\u" + call assert_equal('R-Rc', g:current_modes) + exe "normal RBa\\\u" + call assert_equal('R-Rx', g:current_modes) + exe "normal RBa\\\\u" + call assert_equal('R-Rc', g:current_modes) + exe "normal RBro\\\\u" + call assert_equal('R-Rc', g:current_modes) + exe "normal RBro\\\\\u" + call assert_equal('R-Rc', g:current_modes) + exe "normal RCom\\\u" + call assert_equal('R-Rc', g:current_modes) + exe "normal RCom\\\\u" + call assert_equal('R-Rc', g:current_modes) + + call assert_equal('n', mode(0)) + call assert_equal('n', mode(1)) + " How to test operator-pending mode? + + call feedkeys("v", 'xt') + call assert_equal('v', mode()) + call assert_equal('v', mode(1)) + call feedkeys("\V", 'xt') + call assert_equal('V', mode()) + call assert_equal('V', mode(1)) + call feedkeys("\\", 'xt') + call assert_equal("\", mode()) + call assert_equal("\", mode(1)) + call feedkeys("\", 'xt') + + call feedkeys("gh", 'xt') + call assert_equal('s', mode()) + call assert_equal('s', mode(1)) + call feedkeys("\gH", 'xt') + call assert_equal('S', mode()) + call assert_equal('S', mode(1)) + call feedkeys("\g\", 'xt') + call assert_equal("\", mode()) + call assert_equal("\", mode(1)) + call feedkeys("\", 'xt') + + call feedkeys(":echo \=Save_mode()\\", 'xt') + call assert_equal('c-c', g:current_modes) + call feedkeys("gQecho \=Save_mode()\\vi\", 'xt') + call assert_equal('c-cv', g:current_modes) + " How to test Ex mode? + + bwipe! + iunmap +endfunc diff --git a/src/nvim/testdir/test_mapping.vim b/src/nvim/testdir/test_mapping.vim index 7f93ddd56e..f5e4c4b90c 100644 --- a/src/nvim/testdir/test_mapping.vim +++ b/src/nvim/testdir/test_mapping.vim @@ -110,6 +110,8 @@ func Test_map_langmap() call feedkeys(":call append(line('$'), '+')\", "xt") call assert_equal('+', getline('$')) + iunmap a + iunmap c set nomodified endfunc @@ -120,7 +122,7 @@ func Test_map_feedkeys() $-1 call feedkeys("0qqdw.ifoo\qj0@q\", "xt") call assert_equal(['fooc d', 'fooc d'], getline(line('$') - 1, line('$'))) - unmap . + nunmap . set nomodified endfunc diff --git a/src/nvim/version.c b/src/nvim/version.c index 5accf8f1d6..c73cc0d3ee 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -821,7 +821,7 @@ static const int included_patches[] = { // 286, // 285 NA // 284 NA - // 283, + 283, 282, // 281 NA 280, -- cgit