# HG changeset patch # User Bram Moolenaar # Date 1605360603 -3600 # Node ID 5a7db84713dcadd5d1d096e7ac5c58400ac9c29d # Parent 5f0f170bd19fb80b0d6e8118a07caa9f63c60301 patch 8.2.1983: ml_get error when using to open a terminal Commit: https://github.com/vim/vim/commit/f4d61bc559f8cb6adc4880183a4fd216865c0c30 Author: Bram Moolenaar Date: Sat Nov 14 14:22:28 2020 +0100 patch 8.2.1983: ml_get error when using to open a terminal Problem: ml_get error when using to open a terminal. Solution: If the window changed reset the incsearch state. (closes https://github.com/vim/vim/issues/7289) diff --git a/src/ex_getln.c b/src/ex_getln.c --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -142,6 +142,7 @@ restore_viewstate(viewstate_T *vs) typedef struct { pos_T search_start; // where 'incsearch' starts searching pos_T save_cursor; + int winid; // window where this state is valid viewstate_T init_viewstate; viewstate_T old_viewstate; pos_T match_start; @@ -154,6 +155,7 @@ typedef struct { static void init_incsearch_state(incsearch_state_T *is_state) { + is_state->winid = curwin->w_id; is_state->match_start = curwin->w_cursor; is_state->did_incsearch = FALSE; is_state->incsearch_postponed = FALSE; @@ -1703,13 +1705,13 @@ getcmdline_int( // Trigger SafeState if nothing is pending. may_trigger_safestate(xpc.xp_numfiles <= 0); - cursorcmd(); // set the cursor on the right spot - // Get a character. Ignore K_IGNORE and K_NOP, they should not do // anything, such as stop completion. do + { + cursorcmd(); // set the cursor on the right spot c = safe_vgetc(); - while (c == K_IGNORE || c == K_NOP); + } while (c == K_IGNORE || c == K_NOP); if (c == K_COMMAND && do_cmdline(NULL, getcmdkeycmd, NULL, DOCMD_NOWAIT) == OK) @@ -2327,6 +2329,11 @@ cmdline_not_changed: #endif cmdline_changed: +#ifdef FEAT_SEARCH_EXTRA + // If the window changed incremental search state is not valid. + if (is_state.winid != curwin->w_id) + init_incsearch_state(&is_state); +#endif // Trigger CmdlineChanged autocommands. trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINECHANGED); diff --git a/src/testdir/dumps/Test_terminal_from_cmd.dump b/src/testdir/dumps/Test_terminal_from_cmd.dump new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_terminal_from_cmd.dump @@ -0,0 +1,20 @@ +| +0&#ffffff0@74 +@75 +@75 +@75 +@75 +@75 +@75 +@75 +@75 +|!+2#ffffff16#00e0003|/|b|i|n|/|s|h| |[|f|i|n|i|s|h|e|d|]| @37|0|,|0|-|1| @9|A|l@1 +|a+0#0000000#ffffff0| @73 +|b| @73 +|c| @73 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1| @11|A|l@1 +|/+0&&> @73 diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim --- a/src/testdir/test_terminal.vim +++ b/src/testdir/test_terminal.vim @@ -1200,7 +1200,30 @@ func Test_terminal_open_autocmd() unlet s:called au! repro -endfunction +endfunc + +func Test_open_term_from_cmd() + CheckUnix + CheckRunVimInTerminal + + let lines =<< trim END + call setline(1, ['a', 'b', 'c']) + 3 + set incsearch + cnoremap call term_start(['/bin/sh', '-c', ':']) + END + call writefile(lines, 'Xopenterm') + let buf = RunVimInTerminal('-S Xopenterm', {}) + + " this opens a window, incsearch should not use the old cursor position + call term_sendkeys(buf, "/\") + call VerifyScreenDump(buf, 'Test_terminal_from_cmd', {}) + call term_sendkeys(buf, "\") + call term_sendkeys(buf, ":q\") + + call StopVimInTerminal(buf) + call delete('Xopenterm') +endfunc func Check_dump01(off) call assert_equal('one two three four five', trim(getline(a:off + 1))) diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1983, +/**/ 1982, /**/ 1981,