Skip to content

Commit 6b810d9

Browse files
committed
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.
1 parent c8523e2 commit 6b810d9

File tree

4 files changed

+68
-9
lines changed

4 files changed

+68
-9
lines changed

src/option.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12439,6 +12439,10 @@ check_opt_wim(void)
1243912439
can_bs(
1244012440
int what) /* BS_INDENT, BS_EOL or BS_START */
1244112441
{
12442+
#ifdef FEAT_JOB_CHANNEL
12443+
if (what == BS_START && bt_prompt(curbuf))
12444+
return FALSE;
12445+
#endif
1244212446
switch (*p_bs)
1244312447
{
1244412448
case '2': return TRUE;

src/terminal.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5094,8 +5094,19 @@ f_term_sendkeys(typval_T *argvars, typval_T *rettv)
50945094

50955095
while (*msg != NUL)
50965096
{
5097-
send_keys_to_term(term, PTR2CHAR(msg), FALSE);
5098-
msg += MB_CPTR2LEN(msg);
5097+
int c;
5098+
5099+
if (*msg == K_SPECIAL && msg[1] != NUL && msg[2] != NUL)
5100+
{
5101+
c = TO_SPECIAL(msg[1], msg[2]);
5102+
msg += 3;
5103+
}
5104+
else
5105+
{
5106+
c = PTR2CHAR(msg);
5107+
msg += MB_CPTR2LEN(msg);
5108+
}
5109+
send_keys_to_term(term, c, FALSE);
50995110
}
51005111
}
51015112

src/testdir/test_prompt_buffer.vim

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@ endif
77
source shared.vim
88
source screendump.vim
99

10-
func Test_prompt_basic()
10+
func CanTestPromptBuffer()
1111
" We need to use a terminal window to be able to feed keys without leaving
1212
" Insert mode.
1313
if !has('terminal')
14-
return
14+
return 0
1515
endif
1616
if has('win32')
17-
" TODO: make this work on MS-Windows
18-
return
17+
" TODO: make the tests work on MS-Windows
18+
return 0
1919
endif
20+
return 1
21+
endfunc
22+
23+
func WriteScript(name)
2024
call writefile([
2125
\ 'func TextEntered(text)',
2226
\ ' if a:text == "exit"',
@@ -44,8 +48,17 @@ func Test_prompt_basic()
4448
\ 'set buftype=prompt',
4549
\ 'call prompt_setcallback(bufnr(""), function("TextEntered"))',
4650
\ 'startinsert',
47-
\ ], 'Xpromptscript')
48-
let buf = RunVimInTerminal('-S Xpromptscript', {})
51+
\ ], a:name)
52+
endfunc
53+
54+
func Test_prompt_basic()
55+
if !CanTestPromptBuffer()
56+
return
57+
endif
58+
let scriptName = 'XpromptscriptBasic'
59+
call WriteScript(scriptName)
60+
61+
let buf = RunVimInTerminal('-S ' . scriptName, {})
4962
call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))})
5063

5164
call term_sendkeys(buf, "hello\<CR>")
@@ -57,5 +70,34 @@ func Test_prompt_basic()
5770
call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))})
5871

5972
call StopVimInTerminal(buf)
60-
call delete('Xpromptscript')
73+
call delete(scriptName)
74+
endfunc
75+
76+
func Test_prompt_editing()
77+
if !CanTestPromptBuffer()
78+
return
79+
endif
80+
let scriptName = 'XpromptscriptEditing'
81+
call WriteScript(scriptName)
82+
83+
let buf = RunVimInTerminal('-S ' . scriptName, {})
84+
call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))})
85+
86+
let bs = "\<BS>"
87+
call term_sendkeys(buf, "hello" . bs . bs)
88+
call WaitForAssert({-> assert_equal('% hel', term_getline(buf, 1))})
89+
90+
let left = "\<Left>"
91+
call term_sendkeys(buf, left . left . left . bs . '-')
92+
call WaitForAssert({-> assert_equal('% -hel', term_getline(buf, 1))})
93+
94+
let end = "\<End>"
95+
call term_sendkeys(buf, end . "x")
96+
call WaitForAssert({-> assert_equal('% -helx', term_getline(buf, 1))})
97+
98+
call term_sendkeys(buf, "\<C-U>exit\<CR>")
99+
call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))})
100+
101+
call StopVimInTerminal(buf)
102+
call delete(scriptName)
61103
endfunc

src/version.c

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

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
32,
764766
/**/
765767
31,
766768
/**/

0 commit comments

Comments
 (0)