diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/ex_docmd.c | 7 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 7 | ||||
-rw-r--r-- | src/nvim/getchar.c | 12 | ||||
-rw-r--r-- | src/nvim/main.c | 6 | ||||
-rw-r--r-- | src/nvim/normal.c | 19 | ||||
-rw-r--r-- | src/nvim/option.c | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_goto.vim | 21 | ||||
-rw-r--r-- | src/nvim/testdir/test_normal.vim | 56 |
8 files changed, 105 insertions, 25 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 143c39bc7e..f0e4883fdd 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -6034,10 +6034,11 @@ static void ex_cquit(exarg_T *eap) static void ex_quit_all(exarg_T *eap) { if (cmdwin_type != 0) { - if (eap->forceit) - cmdwin_result = K_XF1; /* ex_window() takes care of this */ - else + if (eap->forceit) { + cmdwin_result = K_XF1; // open_cmdwin() takes care of this + } else { cmdwin_result = K_XF2; + } return; } diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 9b1dcfcafb..774007c66e 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -861,7 +861,7 @@ static int command_line_execute(VimState *state, int key) if (s->c == cedit_key || s->c == K_CMDWIN) { if (ex_normal_busy == 0 && got_int == false) { // Open a window to edit the command line (and history). - s->c = ex_window(); + s->c = open_cmdwin(); s->some_key_typed = true; } } else { @@ -1444,7 +1444,7 @@ static int command_line_handle_key(CommandLineState *s) return command_line_not_changed(s); case K_IGNORE: - // Ignore mouse event or ex_window() result. + // Ignore mouse event or open_cmdwin() result. return command_line_not_changed(s); @@ -6001,7 +6001,7 @@ int cmd_gchar(int offset) * Ctrl_C if it is to be abandoned * K_IGNORE if editing continues */ -static int ex_window(void) +static int open_cmdwin(void) { struct cmdline_info save_ccline; bufref_T old_curbuf; @@ -6034,6 +6034,7 @@ static int ex_window(void) block_autocmds(); /* don't use a new tab page */ cmdmod.tab = 0; + cmdmod.noswapfile = 1; /* Create a window for the command-line buffer. */ if (win_split((int)p_cwh, WSP_BOT) == FAIL) { diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 1c0464b575..a77c467fe5 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -835,7 +835,7 @@ static void init_typebuf(void) typebuf.tb_noremap = noremapbuf_init; typebuf.tb_buflen = TYPELEN_INIT; typebuf.tb_len = 0; - typebuf.tb_off = 0; + typebuf.tb_off = MAXMAPLEN + 4; typebuf.tb_change_cnt = 1; } } @@ -879,9 +879,15 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, bool silent) // Easy case: there is room in front of typebuf.tb_buf[typebuf.tb_off] typebuf.tb_off -= addlen; memmove(typebuf.tb_buf + typebuf.tb_off, str, (size_t)addlen); + } else if (typebuf.tb_len == 0 + && typebuf.tb_buflen >= addlen + 3 * (MAXMAPLEN + 4)) { + // Buffer is empty and string fits in the existing buffer. + // Leave some space before and after, if possible. + typebuf.tb_off = (typebuf.tb_buflen - addlen - 3 * (MAXMAPLEN + 4)) / 2; + memmove(typebuf.tb_buf + typebuf.tb_off, str, (size_t)addlen); } else { // Need to allocate a new buffer. - // In typebuf.tb_buf there must always be room for 3 * MAXMAPLEN + 4 + // In typebuf.tb_buf there must always be room for 3 * (MAXMAPLEN + 4) // characters. We add some extra room to avoid having to allocate too // often. newoff = MAXMAPLEN + 4; @@ -1145,7 +1151,7 @@ void alloc_typebuf(void) typebuf.tb_buf = xmalloc(TYPELEN_INIT); typebuf.tb_noremap = xmalloc(TYPELEN_INIT); typebuf.tb_buflen = TYPELEN_INIT; - typebuf.tb_off = 0; + typebuf.tb_off = MAXMAPLEN + 4; // can insert without realloc typebuf.tb_len = 0; typebuf.tb_maplen = 0; typebuf.tb_silent = 0; diff --git a/src/nvim/main.c b/src/nvim/main.c index ea43b93b30..6aed84aba5 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1410,6 +1410,12 @@ static void read_stdin(void) int save_msg_didany = msg_didany; set_buflisted(true); (void)open_buffer(true, NULL, 0); // create memfile and read file + if (BUFEMPTY() && curbuf->b_next != NULL) { + // stdin was empty, go to buffer 2 (e.g. "echo file1 | xargs nvim"). #8561 + do_cmdline_cmd("silent! bnext"); + // Delete the empty stdin buffer. + do_cmdline_cmd("bwipeout 1"); + } no_wait_return = false; msg_didany = save_msg_didany; TIME_MSG("reading stdin"); diff --git a/src/nvim/normal.c b/src/nvim/normal.c index b959ea08f3..a649777ddd 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3769,14 +3769,17 @@ find_decl ( t = false; /* match after start is failure too */ if (thisblock && t != false) { - pos_T *pos; - - /* Check that the block the match is in doesn't end before the - * position where we started the search from. */ - if ((pos = findmatchlimit(NULL, '}', FM_FORWARD, - (int)(old_pos.lnum - curwin->w_cursor.lnum + 1))) != NULL - && pos->lnum < old_pos.lnum) + const int64_t maxtravel = old_pos.lnum - curwin->w_cursor.lnum + 1; + const pos_T *pos = findmatchlimit(NULL, '}', FM_FORWARD, maxtravel); + + // Check that the block the match is in doesn't end before the + // position where we started the search from. + if (pos != NULL && pos->lnum < old_pos.lnum) { + // There can't be a useful match before the end of this block. + // Skip to the end + curwin->w_cursor = *pos; continue; + } } if (t == false) { @@ -6895,7 +6898,7 @@ static void nv_g_cmd(cmdarg_T *cap) else show_utf8(); break; - + // "g<": show scrollback text case '<': show_sb_text(); break; diff --git a/src/nvim/option.c b/src/nvim/option.c index 0851e6cc5f..68b0a525f1 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -5811,7 +5811,7 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_ml = p_ml; buf->b_p_ml_nobin = p_ml_nobin; buf->b_p_inf = p_inf; - buf->b_p_swf = p_swf; + buf->b_p_swf = cmdmod.noswapfile ? false : p_swf; buf->b_p_cpt = vim_strsave(p_cpt); buf->b_p_cfu = vim_strsave(p_cfu); buf->b_p_ofu = vim_strsave(p_ofu); diff --git a/src/nvim/testdir/test_goto.vim b/src/nvim/testdir/test_goto.vim index 2573401707..ea67fe7386 100644 --- a/src/nvim/testdir/test_goto.vim +++ b/src/nvim/testdir/test_goto.vim @@ -288,3 +288,24 @@ func Test_cursorline_keep_col() set nocursorline endfunc +func Test_gd_local_block() + let lines = [ + \ ' int main()', + \ '{', + \ ' char *a = "NOT NULL";', + \ ' if(a)', + \ ' {', + \ ' char *b = a;', + \ ' printf("%s\n", b);', + \ ' }', + \ ' else', + \ ' {', + \ ' char *b = "NULL";', + \ ' return b;', + \ ' }', + \ '', + \ ' return 0;', + \ '}', + \ ] + call XTest_goto_decl('1gd', lines, 11, 11) +endfunc diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 27ac084ef0..c638920dd3 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -847,7 +847,7 @@ func! Test_normal18_z_fold() norm! j call assert_equal('52', getline('.')) - " zA on a opened fold when foldenale is not set + " zA on a opened fold when foldenable is not set 50 set nofoldenable norm! zA @@ -909,7 +909,7 @@ func! Test_normal18_z_fold() norm! j call assert_equal('55', getline('.')) - " 2) do not close fold under curser + " 2) do not close fold under cursor 51 set nofoldenable norm! zx @@ -1829,18 +1829,60 @@ fun! Test_normal34_g_cmd3() if !has("multi_byte") return endif + " Test for g8 new - call append(0, 'abcdefghijklmnopqrstuvwxyzäüö') - let a=execute(':norm! 1gg$g8') - call assert_equal('c3 b6 ', a[1:]) + let a=execute(':norm! 1G0g8') + call assert_equal("\nNUL", a) + + call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö') + let a=execute(':norm! 1G$g8') + call assert_equal("\nc3 b6 ", a) + + call setline(1, "a\u0302") + let a=execute(':norm! 1G0g8') + call assert_equal("\n61 + cc 82 ", a) - " Test for gp gP - call append(1, range(1,10)) " clean up bw! endfunc +func Test_normal_8g8() + if !has("multi_byte") + return + endif + new + + " Test 8g8 which finds invalid utf8 at or after the cursor. + + " With invalid byte. + call setline(1, "___\xff___") + norm! 1G08g8g + call assert_equal([0, 1, 4, 0, 1], getcurpos()) + + " With invalid byte before the cursor. + call setline(1, "___\xff___") + norm! 1G$h8g8g + call assert_equal([0, 1, 6, 0, 9], getcurpos()) + + " With truncated sequence. + call setline(1, "___\xE2\x82___") + norm! 1G08g8g + call assert_equal([0, 1, 4, 0, 1], getcurpos()) + + " With overlong sequence. + call setline(1, "___\xF0\x82\x82\xAC___") + norm! 1G08g8g + call assert_equal([0, 1, 4, 0, 1], getcurpos()) + + " With valid utf8. + call setline(1, "café") + norm! 1G08g8 + call assert_equal([0, 1, 1, 0, 1], getcurpos()) + + bw! +endfunc + fun! Test_normal35_g_cmd4() " Test for g< " Cannot capture its output, |