diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/ex_getln.c | 34 | ||||
-rw-r--r-- | src/nvim/testdir/test_autocmd.vim | 31 | ||||
-rw-r--r-- | src/nvim/testdir/test_gf.vim | 27 | ||||
-rw-r--r-- | src/nvim/testdir/test_search.vim | 18 | ||||
-rw-r--r-- | src/nvim/window.c | 6 |
5 files changed, 103 insertions, 13 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 8f2d536e63..f9ca7bfa42 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -288,6 +288,7 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, exarg_T ea; pos_T save_cursor; bool use_last_pat; + bool retval = false; *skiplen = 0; *patlen = ccline.cmdlen; @@ -307,6 +308,7 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, return false; } + emsg_off++; memset(&ea, 0, sizeof(ea)); ea.line1 = 1; ea.line2 = 1; @@ -318,13 +320,13 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, cmd = skip_range(ea.cmd, NULL); if (vim_strchr((char_u *)"sgvl", *cmd) == NULL) { - return false; + goto theend; } // Skip over "substitute" to find the pattern separator. for (p = cmd; ASCII_ISALPHA(*p); p++) {} if (*skipwhite(p) == NUL) { - return false; + goto theend; } if (STRNCMP(cmd, "substitute", p - cmd) == 0 @@ -337,12 +339,15 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, p_magic = false; } } else if (STRNCMP(cmd, "sort", MAX(p - cmd, 3)) == 0) { - // skip over flags. + // skip over ! and flags + if (*p == '!') { + p = skipwhite(p + 1); + } while (ASCII_ISALPHA(*(p = skipwhite(p)))) { p++; } if (*p == NUL) { - return false; + goto theend; } } else if (STRNCMP(cmd, "vimgrep", MAX(p - cmd, 3)) == 0 || STRNCMP(cmd, "vimgrepadd", MAX(p - cmd, 8)) == 0 @@ -353,14 +358,14 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, if (*p == '!') { p++; if (*skipwhite(p) == NUL) { - return false; + goto theend; } } if (*cmd != 'g') { delim_optional = true; } } else { - return false; + goto theend; } p = skipwhite(p); @@ -369,7 +374,7 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, use_last_pat = end == p && *end == delim; if (end == p && !use_last_pat) { - return false; + goto theend; } // Don't do 'hlsearch' highlighting if the pattern matches everything. @@ -381,7 +386,7 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, empty = empty_pattern(p); *end = c; if (empty) { - return false; + goto theend; } } @@ -409,7 +414,10 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, } curwin->w_cursor = save_cursor; - return true; + retval = true; +theend: + emsg_off--; + return retval; } // May do 'incsearch' highlighting if desired. @@ -549,6 +557,7 @@ static void may_do_incsearch_highlighting(int firstc, long count, } update_screen(SOME_VALID); + highlight_match = false; restore_last_search_pattern(); // Leave it at the end to make CTRL-R CTRL-W work. But not when beyond the @@ -1541,6 +1550,7 @@ static int may_do_command_line_next_incsearch(int firstc, long count, highlight_match = true; save_viewstate(&s->old_viewstate); update_screen(NOT_VALID); + highlight_match = false; redrawcmdline(); curwin->w_cursor = s->match_end; } else { @@ -6463,12 +6473,15 @@ static int open_cmdwin(void) // Save the command line info, can be used recursively. save_cmdline(&save_ccline); - /* No Ex mode here! */ + // No Ex mode here! exmode_active = 0; State = NORMAL; setmouse(); + // Reset here so it can be set by a CmdWinEnter autocommand. + cmdwin_result = 0; + // Trigger CmdwinEnter autocommands. typestr[0] = (char_u)cmdwin_type; typestr[1] = NUL; @@ -6484,7 +6497,6 @@ static int open_cmdwin(void) /* * Call the main loop until <CR> or CTRL-C is typed. */ - cmdwin_result = 0; normal_enter(true, false); RedrawingDisabled = i; diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 3dd68873d4..094bb3ebd1 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -1,6 +1,8 @@ " Tests for autocommands source shared.vim +source check.vim +source term_util.vim func! s:cleanup_buffers() abort for bnr in range(1, bufnr('$')) @@ -1735,6 +1737,35 @@ func Test_throw_in_BufWritePre() au! throwing endfunc +func Test_autocmd_CmdWinEnter() + CheckRunVimInTerminal + " There is not cmdwin switch, so + " test for cmdline_hist + " (both are available with small builds) + CheckFeature cmdline_hist + let lines =<< trim END + let b:dummy_var = 'This is a dummy' + autocmd CmdWinEnter * quit + let winnr = winnr('$') + END + let filename='XCmdWinEnter' + call writefile(lines, filename) + let buf = RunVimInTerminal('-S '.filename, #{rows: 6}) + + call term_sendkeys(buf, "q:") + call term_wait(buf) + call term_sendkeys(buf, ":echo b:dummy_var\<cr>") + call WaitForAssert({-> assert_match('^This is a dummy', term_getline(buf, 6))}, 1000) + call term_sendkeys(buf, ":echo &buftype\<cr>") + call WaitForAssert({-> assert_notmatch('^nofile', term_getline(buf, 6))}, 1000) + call term_sendkeys(buf, ":echo winnr\<cr>") + call WaitForAssert({-> assert_match('^1', term_getline(buf, 6))}, 1000) + + " clean up + call StopVimInTerminal(buf) + call delete(filename) +endfunc + func Test_FileChangedShell_reload() if !has('unix') return diff --git a/src/nvim/testdir/test_gf.vim b/src/nvim/testdir/test_gf.vim index 4a4ffcefa1..ee548037ba 100644 --- a/src/nvim/testdir/test_gf.vim +++ b/src/nvim/testdir/test_gf.vim @@ -1,3 +1,4 @@ +" Test for the gf and gF (goto file) commands " This is a test if a URL is recognized by "gf", with the cursor before and " after the "://". Also test ":\\". @@ -109,7 +110,7 @@ func Test_gf() endfunc func Test_gf_visual() - call writefile([], "Xtest_gf_visual") + call writefile(['one', 'two', 'three', 'four'], "Xtest_gf_visual") new call setline(1, 'XXXtest_gf_visualXXX') set hidden @@ -118,6 +119,30 @@ func Test_gf_visual() norm! ttvtXgf call assert_equal('Xtest_gf_visual', bufname('%')) + " if multiple lines are selected, then gf should fail + call setline(1, ["one", "two"]) + normal VGgf + call assert_equal('Xtest_gf_visual', @%) + + " following line number is used for gF + bwipe! + new + call setline(1, 'XXXtest_gf_visual:3XXX') + norm! 0ttvt:gF + call assert_equal('Xtest_gf_visual', bufname('%')) + call assert_equal(3, getcurpos()[1]) + + " line number in visual area is used for file name + if has('unix') + bwipe! + call writefile([], "Xtest_gf_visual:3") + new + call setline(1, 'XXXtest_gf_visual:3XXX') + norm! 0ttvtXgF + call assert_equal('Xtest_gf_visual:3', bufname('%')) + call delete('Xtest_gf_visual:3') + endif + bwipe! call delete('Xtest_gf_visual') set hidden& diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index e3a0fce5a6..211fc73562 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -708,6 +708,19 @@ func Test_incsearch_substitute_dump() call VerifyScreenDump(buf, 'Test_incsearch_substitute_12', {}) call term_sendkeys(buf, "\<Esc>") call VerifyScreenDump(buf, 'Test_incsearch_substitute_13', {}) + call term_sendkeys(buf, ":%bwipe!\<CR>") + call term_sendkeys(buf, ":only!\<CR>") + + " get :'<,'>s command in history + call term_sendkeys(buf, ":set cmdheight=2\<CR>") + call term_sendkeys(buf, "aasdfasdf\<Esc>") + call term_sendkeys(buf, "V:s/a/b/g\<CR>") + " Using '<,'> does not give E20 + call term_sendkeys(buf, ":new\<CR>") + call term_sendkeys(buf, "aasdfasdf\<Esc>") + call term_sendkeys(buf, ":\<Up>\<Up>") + call VerifyScreenDump(buf, 'Test_incsearch_substitute_14', {}) + call term_sendkeys(buf, "<Esc>") call StopVimInTerminal(buf) call delete('Xis_subst_script') @@ -730,11 +743,14 @@ func Test_incsearch_sort_dump() " the 'ambiwidth' check. sleep 100m - " Need to send one key at a time to force a redraw. call term_sendkeys(buf, ':sort ni u /on') call VerifyScreenDump(buf, 'Test_incsearch_sort_01', {}) call term_sendkeys(buf, "\<Esc>") + call term_sendkeys(buf, ':sort! /on') + call VerifyScreenDump(buf, 'Test_incsearch_sort_02', {}) + call term_sendkeys(buf, "\<Esc>") + call StopVimInTerminal(buf) call delete('Xis_sort_script') endfunc diff --git a/src/nvim/window.c b/src/nvim/window.c index cec0dfd67f..6608deb231 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -6019,6 +6019,12 @@ char_u *grab_file_name(long count, linenr_T *file_lnum) char_u *ptr; if (get_visual_text(NULL, &ptr, &len) == FAIL) return NULL; + // Only recognize ":123" here + if (file_lnum != NULL && ptr[len] == ':' && isdigit(ptr[len + 1])) { + char_u *p = ptr + len + 1; + + *file_lnum = getdigits_long(&p, false, 0); + } return find_file_name_in_path(ptr, len, options, count, curbuf->b_ffname); } return file_name_at_cursor(options | FNAME_HYP, count, file_lnum); |