term: after <C-\>, resume normal input loop

Pressing <C-\> and then a mouse click will insert the click into the
terminal as if a keyboard button had been pressed.

Keep track of whether the last input was <C-\> and only call
terminal_send_key() if the next input is a key press.
This commit is contained in:
Scott Prager
2015-04-05 13:20:08 -04:00
parent b6296f4e84
commit b8ae09b3cf
3 changed files with 31 additions and 10 deletions

View File

@@ -376,6 +376,8 @@ void terminal_enter(bool process_deferred)
int c; int c;
bool close = false; bool close = false;
bool got_bs = false; // True if the last input was <C-\>
while (term->buf == curbuf) { while (term->buf == curbuf) {
if (process_deferred) { if (process_deferred) {
event_enable_deferred(); event_enable_deferred();
@@ -388,14 +390,6 @@ void terminal_enter(bool process_deferred)
} }
switch (c) { switch (c) {
case Ctrl_BSL:
c = safe_vgetc();
if (c == Ctrl_N) {
goto end;
}
terminal_send_key(term, c);
break;
case K_LEFTMOUSE: case K_LEFTMOUSE:
case K_LEFTDRAG: case K_LEFTDRAG:
case K_LEFTRELEASE: case K_LEFTRELEASE:
@@ -416,12 +410,22 @@ void terminal_enter(bool process_deferred)
event_process(); event_process();
break; break;
case Ctrl_N:
if (got_bs) {
goto end;
}
default: default:
if (c == Ctrl_BSL && !got_bs) {
got_bs = true;
break;
}
if (term->closed) { if (term->closed) {
close = true; close = true;
goto end; goto end;
} }
got_bs = false;
terminal_send_key(term, c); terminal_send_key(term, c);
} }
} }

View File

@@ -170,15 +170,18 @@ describe('terminal buffer', function()
source([[ source([[
function! SplitWindow() function! SplitWindow()
new new
call feedkeys("iabc\<Esc>")
endfunction endfunction
startinsert startinsert
call jobstart(['sh', '-c', 'exit'], {'on_exit': function("SplitWindow")}) call jobstart(['sh', '-c', 'exit'], {'on_exit': function("SplitWindow")})
call feedkeys("\<C-\>", 't') " vim will expect <C-n>, but be exited out of
" the terminal before it can be entered.
]]) ]])
-- We should be in a new buffer now. -- We should be in a new buffer now.
screen:expect([[ screen:expect([[
^ | ab^c |
~ | ~ |
========== | ========== |
rows: 2, cols: 50 | rows: 2, cols: 50 |
@@ -188,7 +191,7 @@ describe('terminal buffer', function()
]]) ]])
neq(tbuf, eval('bufnr("%")')) neq(tbuf, eval('bufnr("%")'))
execute('quit') -- Should exit the new window, not the terminal. execute('quit!') -- Should exit the new window, not the terminal.
eq(tbuf, eval('bufnr("%")')) eq(tbuf, eval('bufnr("%")'))
execute('set laststatus=1') -- Restore laststatus to the default. execute('set laststatus=1') -- Restore laststatus to the default.

View File

@@ -50,6 +50,20 @@ describe('terminal mouse', function()
]]) ]])
end) end)
it('will exit focus after <C-\\>, then scrolled', function()
feed('<C-\\>')
feed('<MouseDown><0,0>')
screen:expect([[
line23 |
line24 |
line25 |
line26 |
line27 |
^line28 |
|
]])
end)
describe('with mouse events enabled by the program', function() describe('with mouse events enabled by the program', function()
before_each(function() before_each(function()
thelpers.enable_mouse() thelpers.enable_mouse()