Skip to content
Snippets Groups Projects
Commit 27321dbe authored by Bram Moolenaar's avatar Bram Moolenaar
Browse files

patch 8.2.1147: :confirm may happen in cooked mode

Problem:    :confirm may happen in cooked mode. (Jason Franklin)
Solution:   Switch to raw mode before prompting. (Brandon Pfeifer)
parent ab589463
No related branches found
Tags v8.2.1147
No related merge requests found
...@@ -3652,6 +3652,7 @@ do_dialog( ...@@ -3652,6 +3652,7 @@ do_dialog(
char_u *hotkeys; char_u *hotkeys;
int c; int c;
int i; int i;
tmode_T save_tmode;
#ifndef NO_CONSOLE #ifndef NO_CONSOLE
// Don't output anything in silent mode ("ex -s") // Don't output anything in silent mode ("ex -s")
...@@ -3683,6 +3684,10 @@ do_dialog( ...@@ -3683,6 +3684,10 @@ do_dialog(
State = CONFIRM; State = CONFIRM;
setmouse(); setmouse();
// Ensure raw mode here.
save_tmode = cur_tmode;
settmode(TMODE_RAW);
/* /*
* Since we wait for a keypress, don't make the * Since we wait for a keypress, don't make the
* user press RETURN as well afterwards. * user press RETURN as well afterwards.
...@@ -3743,6 +3748,7 @@ do_dialog( ...@@ -3743,6 +3748,7 @@ do_dialog(
vim_free(hotkeys); vim_free(hotkeys);
} }
settmode(save_tmode);
State = oldState; State = oldState;
setmouse(); setmouse();
--no_wait_return; --no_wait_return;
......
...@@ -189,49 +189,58 @@ func Test_confirm_cmd() ...@@ -189,49 +189,58 @@ func Test_confirm_cmd()
CheckNotGui CheckNotGui
CheckRunVimInTerminal CheckRunVimInTerminal
call writefile(['foo1'], 'foo') call writefile(['foo1'], 'Xfoo')
call writefile(['bar1'], 'bar') call writefile(['bar1'], 'Xbar')
" Test for saving all the modified buffers " Test for saving all the modified buffers
let buf = RunVimInTerminal('', {'rows': 20}) let lines =<< trim END
call term_sendkeys(buf, ":set nomore\n") set nomore
call term_sendkeys(buf, ":new foo\n") new Xfoo
call term_sendkeys(buf, ":call setline(1, 'foo2')\n") call setline(1, 'foo2')
call term_sendkeys(buf, ":new bar\n") new Xbar
call term_sendkeys(buf, ":call setline(1, 'bar2')\n") call setline(1, 'bar2')
call term_sendkeys(buf, ":wincmd b\n") wincmd b
END
call writefile(lines, 'Xscript')
let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
call term_sendkeys(buf, ":confirm qall\n") call term_sendkeys(buf, ":confirm qall\n")
call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000) call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000)
call term_sendkeys(buf, "A") call term_sendkeys(buf, "A")
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
call assert_equal(['foo2'], readfile('foo')) call assert_equal(['foo2'], readfile('Xfoo'))
call assert_equal(['bar2'], readfile('bar')) call assert_equal(['bar2'], readfile('Xbar'))
" Test for discarding all the changes to modified buffers " Test for discarding all the changes to modified buffers
let buf = RunVimInTerminal('', {'rows': 20}) let lines =<< trim END
call term_sendkeys(buf, ":set nomore\n") set nomore
call term_sendkeys(buf, ":new foo\n") new Xfoo
call term_sendkeys(buf, ":call setline(1, 'foo3')\n") call setline(1, 'foo3')
call term_sendkeys(buf, ":new bar\n") new Xbar
call term_sendkeys(buf, ":call setline(1, 'bar3')\n") call setline(1, 'bar3')
call term_sendkeys(buf, ":wincmd b\n") wincmd b
END
call writefile(lines, 'Xscript')
let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
call term_sendkeys(buf, ":confirm qall\n") call term_sendkeys(buf, ":confirm qall\n")
call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000) call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000)
call term_sendkeys(buf, "D") call term_sendkeys(buf, "D")
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
call assert_equal(['foo2'], readfile('foo')) call assert_equal(['foo2'], readfile('Xfoo'))
call assert_equal(['bar2'], readfile('bar')) call assert_equal(['bar2'], readfile('Xbar'))
" Test for saving and discarding changes to some buffers " Test for saving and discarding changes to some buffers
let buf = RunVimInTerminal('', {'rows': 20}) let lines =<< trim END
call term_sendkeys(buf, ":set nomore\n") set nomore
call term_sendkeys(buf, ":new foo\n") new Xfoo
call term_sendkeys(buf, ":call setline(1, 'foo4')\n") call setline(1, 'foo4')
call term_sendkeys(buf, ":new bar\n") new Xbar
call term_sendkeys(buf, ":call setline(1, 'bar4')\n") call setline(1, 'bar4')
call term_sendkeys(buf, ":wincmd b\n") wincmd b
END
call writefile(lines, 'Xscript')
let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
call term_sendkeys(buf, ":confirm qall\n") call term_sendkeys(buf, ":confirm qall\n")
call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000) call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000)
call term_sendkeys(buf, "N") call term_sendkeys(buf, "N")
...@@ -239,11 +248,12 @@ func Test_confirm_cmd() ...@@ -239,11 +248,12 @@ func Test_confirm_cmd()
call term_sendkeys(buf, "Y") call term_sendkeys(buf, "Y")
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
call assert_equal(['foo4'], readfile('foo')) call assert_equal(['foo4'], readfile('Xfoo'))
call assert_equal(['bar2'], readfile('bar')) call assert_equal(['bar2'], readfile('Xbar'))
call delete('foo') call delete('Xscript')
call delete('bar') call delete('Xfoo')
call delete('Xbar')
endfunc endfunc
func Test_confirm_cmd_cancel() func Test_confirm_cmd_cancel()
...@@ -251,10 +261,13 @@ func Test_confirm_cmd_cancel() ...@@ -251,10 +261,13 @@ func Test_confirm_cmd_cancel()
CheckRunVimInTerminal CheckRunVimInTerminal
" Test for closing a window with a modified buffer " Test for closing a window with a modified buffer
let buf = RunVimInTerminal('', {'rows': 20}) let lines =<< trim END
call term_sendkeys(buf, ":set nomore\n") set nomore
call term_sendkeys(buf, ":new\n") new
call term_sendkeys(buf, ":call setline(1, 'abc')\n") call setline(1, 'abc')
END
call writefile(lines, 'Xscript')
let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
call term_sendkeys(buf, ":confirm close\n") call term_sendkeys(buf, ":confirm close\n")
call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$',
\ term_getline(buf, 20))}, 1000) \ term_getline(buf, 20))}, 1000)
...@@ -267,6 +280,43 @@ func Test_confirm_cmd_cancel() ...@@ -267,6 +280,43 @@ func Test_confirm_cmd_cancel()
call WaitForAssert({-> assert_match('^ *0,0-1 All$', call WaitForAssert({-> assert_match('^ *0,0-1 All$',
\ term_getline(buf, 20))}, 1000) \ term_getline(buf, 20))}, 1000)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
call delete('Xscript')
endfunc
" The ":confirm" prompt was sometimes used with the terminal in cooked mode.
" This test verifies that a "\<CR>" character is NOT required to respond to a
" prompt from the ":conf q" and ":conf wq" commands.
func Test_confirm_q_wq()
CheckNotGui
CheckRunVimInTerminal
call writefile(['foo'], 'Xfoo')
let lines =<< trim END
set hidden nomore
call setline(1, 'abc')
edit Xfoo
END
call writefile(lines, 'Xscript')
let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
call term_sendkeys(buf, ":confirm q\n")
call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$',
\ term_getline(buf, 20))}, 1000)
call term_sendkeys(buf, 'C')
call WaitForAssert({-> assert_notmatch('^\[Y\]es, (N)o, (C)ancel: C*$',
\ term_getline(buf, 20))}, 1000)
call term_sendkeys(buf, ":edit Xfoo\n")
call term_sendkeys(buf, ":confirm wq\n")
call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$',
\ term_getline(buf, 20))}, 1000)
call term_sendkeys(buf, 'C')
call WaitForAssert({-> assert_notmatch('^\[Y\]es, (N)o, (C)ancel: C*$',
\ term_getline(buf, 20))}, 1000)
call StopVimInTerminal(buf)
call delete('Xscript')
call delete('Xfoo')
endfunc endfunc
" Test for the :print command " Test for the :print command
......
...@@ -754,6 +754,8 @@ static char *(features[]) = ...@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1147,
/**/ /**/
1146, 1146,
/**/ /**/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment