Skip to content

Commit f4d61bc

Browse files
committed
patch 8.2.1983: ml_get error when using <Cmd> to open a terminal
Problem: ml_get error when using <Cmd> to open a terminal. Solution: If the window changed reset the incsearch state. (closes #7289)
1 parent 2ce7790 commit f4d61bc

4 files changed

Lines changed: 56 additions & 4 deletions

File tree

src/ex_getln.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ restore_viewstate(viewstate_T *vs)
142142
typedef struct {
143143
pos_T search_start; // where 'incsearch' starts searching
144144
pos_T save_cursor;
145+
int winid; // window where this state is valid
145146
viewstate_T init_viewstate;
146147
viewstate_T old_viewstate;
147148
pos_T match_start;
@@ -154,6 +155,7 @@ typedef struct {
154155
static void
155156
init_incsearch_state(incsearch_state_T *is_state)
156157
{
158+
is_state->winid = curwin->w_id;
157159
is_state->match_start = curwin->w_cursor;
158160
is_state->did_incsearch = FALSE;
159161
is_state->incsearch_postponed = FALSE;
@@ -1703,13 +1705,13 @@ getcmdline_int(
17031705
// Trigger SafeState if nothing is pending.
17041706
may_trigger_safestate(xpc.xp_numfiles <= 0);
17051707

1706-
cursorcmd(); // set the cursor on the right spot
1707-
17081708
// Get a character. Ignore K_IGNORE and K_NOP, they should not do
17091709
// anything, such as stop completion.
17101710
do
1711+
{
1712+
cursorcmd(); // set the cursor on the right spot
17111713
c = safe_vgetc();
1712-
while (c == K_IGNORE || c == K_NOP);
1714+
} while (c == K_IGNORE || c == K_NOP);
17131715

17141716
if (c == K_COMMAND
17151717
&& do_cmdline(NULL, getcmdkeycmd, NULL, DOCMD_NOWAIT) == OK)
@@ -2327,6 +2329,11 @@ getcmdline_int(
23272329
#endif
23282330

23292331
cmdline_changed:
2332+
#ifdef FEAT_SEARCH_EXTRA
2333+
// If the window changed incremental search state is not valid.
2334+
if (is_state.winid != curwin->w_id)
2335+
init_incsearch_state(&is_state);
2336+
#endif
23302337
// Trigger CmdlineChanged autocommands.
23312338
trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINECHANGED);
23322339

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
| +0&#ffffff0@74
2+
@75
3+
@75
4+
@75
5+
@75
6+
@75
7+
@75
8+
@75
9+
@75
10+
|!+2#ffffff16#00e0003|/|b|i|n|/|s|h| |[|f|i|n|i|s|h|e|d|]| @37|0|,|0|-|1| @9|A|l@1
11+
|a+0#0000000#ffffff0| @73
12+
|b| @73
13+
|c| @73
14+
|~+0#4040ff13&| @73
15+
|~| @73
16+
|~| @73
17+
|~| @73
18+
|~| @73
19+
|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1| @11|A|l@1
20+
|/+0&&> @73

src/testdir/test_terminal.vim

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,30 @@ func Test_terminal_open_autocmd()
12001200

12011201
unlet s:called
12021202
au! repro
1203-
endfunction
1203+
endfunc
1204+
1205+
func Test_open_term_from_cmd()
1206+
CheckUnix
1207+
CheckRunVimInTerminal
1208+
1209+
let lines =<< trim END
1210+
call setline(1, ['a', 'b', 'c'])
1211+
3
1212+
set incsearch
1213+
cnoremap <F3> <Cmd>call term_start(['/bin/sh', '-c', ':'])<CR>
1214+
END
1215+
call writefile(lines, 'Xopenterm')
1216+
let buf = RunVimInTerminal('-S Xopenterm', {})
1217+
1218+
" this opens a window, incsearch should not use the old cursor position
1219+
call term_sendkeys(buf, "/\<F3>")
1220+
call VerifyScreenDump(buf, 'Test_terminal_from_cmd', {})
1221+
call term_sendkeys(buf, "\<Esc>")
1222+
call term_sendkeys(buf, ":q\<CR>")
1223+
1224+
call StopVimInTerminal(buf)
1225+
call delete('Xopenterm')
1226+
endfunc
12041227

12051228
func Check_dump01(off)
12061229
call assert_equal('one two three four five', trim(getline(a:off + 1)))

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
1983,
753755
/**/
754756
1982,
755757
/**/

0 commit comments

Comments
 (0)