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)
diff --git a/src/testdir/dumps/Test_terminal_from_cmd.dump b/src/testdir/dumps/Test_terminal_from_cmd.dump
new file mode 100644
index 0000000..5eea73f
--- /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
index 16ad720..137a8a6 100644
--- a/src/testdir/test_terminal.vim
+++ b/src/testdir/test_terminal.vim
@@ -1200,7 +1200,30 @@
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 <F3> <Cmd>call term_start(['/bin/sh', '-c', ':'])<CR>
+ 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, "/\<F3>")
+ call VerifyScreenDump(buf, 'Test_terminal_from_cmd', {})
+ call term_sendkeys(buf, "\<Esc>")
+ call term_sendkeys(buf, ":q\<CR>")
+
+ call StopVimInTerminal(buf)
+ call delete('Xopenterm')
+endfunc
func Check_dump01(off)
call assert_equal('one two three four five', trim(getline(a:off + 1)))