mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.1.0032: BS in prompt buffer starts new line
Problem: BS in prompt buffer starts new line. Solution: Do not allows BS over the prompt. Make term_sendkeys() handle special keys. Add a test.
This commit is contained in:
parent
c8523e2e6c
commit
6b810d92a9
@ -12439,6 +12439,10 @@ check_opt_wim(void)
|
|||||||
can_bs(
|
can_bs(
|
||||||
int what) /* BS_INDENT, BS_EOL or BS_START */
|
int what) /* BS_INDENT, BS_EOL or BS_START */
|
||||||
{
|
{
|
||||||
|
#ifdef FEAT_JOB_CHANNEL
|
||||||
|
if (what == BS_START && bt_prompt(curbuf))
|
||||||
|
return FALSE;
|
||||||
|
#endif
|
||||||
switch (*p_bs)
|
switch (*p_bs)
|
||||||
{
|
{
|
||||||
case '2': return TRUE;
|
case '2': return TRUE;
|
||||||
|
@ -5094,8 +5094,19 @@ f_term_sendkeys(typval_T *argvars, typval_T *rettv)
|
|||||||
|
|
||||||
while (*msg != NUL)
|
while (*msg != NUL)
|
||||||
{
|
{
|
||||||
send_keys_to_term(term, PTR2CHAR(msg), FALSE);
|
int c;
|
||||||
msg += MB_CPTR2LEN(msg);
|
|
||||||
|
if (*msg == K_SPECIAL && msg[1] != NUL && msg[2] != NUL)
|
||||||
|
{
|
||||||
|
c = TO_SPECIAL(msg[1], msg[2]);
|
||||||
|
msg += 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
c = PTR2CHAR(msg);
|
||||||
|
msg += MB_CPTR2LEN(msg);
|
||||||
|
}
|
||||||
|
send_keys_to_term(term, c, FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,16 +7,20 @@ endif
|
|||||||
source shared.vim
|
source shared.vim
|
||||||
source screendump.vim
|
source screendump.vim
|
||||||
|
|
||||||
func Test_prompt_basic()
|
func CanTestPromptBuffer()
|
||||||
" We need to use a terminal window to be able to feed keys without leaving
|
" We need to use a terminal window to be able to feed keys without leaving
|
||||||
" Insert mode.
|
" Insert mode.
|
||||||
if !has('terminal')
|
if !has('terminal')
|
||||||
return
|
return 0
|
||||||
endif
|
endif
|
||||||
if has('win32')
|
if has('win32')
|
||||||
" TODO: make this work on MS-Windows
|
" TODO: make the tests work on MS-Windows
|
||||||
return
|
return 0
|
||||||
endif
|
endif
|
||||||
|
return 1
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func WriteScript(name)
|
||||||
call writefile([
|
call writefile([
|
||||||
\ 'func TextEntered(text)',
|
\ 'func TextEntered(text)',
|
||||||
\ ' if a:text == "exit"',
|
\ ' if a:text == "exit"',
|
||||||
@ -44,8 +48,17 @@ func Test_prompt_basic()
|
|||||||
\ 'set buftype=prompt',
|
\ 'set buftype=prompt',
|
||||||
\ 'call prompt_setcallback(bufnr(""), function("TextEntered"))',
|
\ 'call prompt_setcallback(bufnr(""), function("TextEntered"))',
|
||||||
\ 'startinsert',
|
\ 'startinsert',
|
||||||
\ ], 'Xpromptscript')
|
\ ], a:name)
|
||||||
let buf = RunVimInTerminal('-S Xpromptscript', {})
|
endfunc
|
||||||
|
|
||||||
|
func Test_prompt_basic()
|
||||||
|
if !CanTestPromptBuffer()
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
let scriptName = 'XpromptscriptBasic'
|
||||||
|
call WriteScript(scriptName)
|
||||||
|
|
||||||
|
let buf = RunVimInTerminal('-S ' . scriptName, {})
|
||||||
call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))})
|
call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))})
|
||||||
|
|
||||||
call term_sendkeys(buf, "hello\<CR>")
|
call term_sendkeys(buf, "hello\<CR>")
|
||||||
@ -57,5 +70,34 @@ func Test_prompt_basic()
|
|||||||
call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))})
|
call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))})
|
||||||
|
|
||||||
call StopVimInTerminal(buf)
|
call StopVimInTerminal(buf)
|
||||||
call delete('Xpromptscript')
|
call delete(scriptName)
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_prompt_editing()
|
||||||
|
if !CanTestPromptBuffer()
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
let scriptName = 'XpromptscriptEditing'
|
||||||
|
call WriteScript(scriptName)
|
||||||
|
|
||||||
|
let buf = RunVimInTerminal('-S ' . scriptName, {})
|
||||||
|
call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))})
|
||||||
|
|
||||||
|
let bs = "\<BS>"
|
||||||
|
call term_sendkeys(buf, "hello" . bs . bs)
|
||||||
|
call WaitForAssert({-> assert_equal('% hel', term_getline(buf, 1))})
|
||||||
|
|
||||||
|
let left = "\<Left>"
|
||||||
|
call term_sendkeys(buf, left . left . left . bs . '-')
|
||||||
|
call WaitForAssert({-> assert_equal('% -hel', term_getline(buf, 1))})
|
||||||
|
|
||||||
|
let end = "\<End>"
|
||||||
|
call term_sendkeys(buf, end . "x")
|
||||||
|
call WaitForAssert({-> assert_equal('% -helx', term_getline(buf, 1))})
|
||||||
|
|
||||||
|
call term_sendkeys(buf, "\<C-U>exit\<CR>")
|
||||||
|
call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))})
|
||||||
|
|
||||||
|
call StopVimInTerminal(buf)
|
||||||
|
call delete(scriptName)
|
||||||
endfunc
|
endfunc
|
||||||
|
@ -761,6 +761,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 */
|
||||||
|
/**/
|
||||||
|
32,
|
||||||
/**/
|
/**/
|
||||||
31,
|
31,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user