mirror of
https://github.com/neovim/neovim.git
synced 2025-11-08 19:45:12 +00:00
Merge #8888 from janlazo/vim-8.0.1020
This commit is contained in:
@@ -434,9 +434,8 @@ void flush_buffers(int flush_typeahead)
|
|||||||
* of an escape sequence.
|
* of an escape sequence.
|
||||||
* In an xterm we get one char at a time and we have to get them all.
|
* In an xterm we get one char at a time and we have to get them all.
|
||||||
*/
|
*/
|
||||||
while (inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 10L,
|
while (inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 10L) != 0) {
|
||||||
typebuf.tb_change_cnt) != 0)
|
}
|
||||||
;
|
|
||||||
typebuf.tb_off = MAXMAPLEN;
|
typebuf.tb_off = MAXMAPLEN;
|
||||||
typebuf.tb_len = 0;
|
typebuf.tb_len = 0;
|
||||||
// Reset the flag that text received from a client or from feedkeys()
|
// Reset the flag that text received from a client or from feedkeys()
|
||||||
@@ -1697,22 +1696,20 @@ static int vgetorpeek(int advance)
|
|||||||
os_breakcheck(); /* check for CTRL-C */
|
os_breakcheck(); /* check for CTRL-C */
|
||||||
keylen = 0;
|
keylen = 0;
|
||||||
if (got_int) {
|
if (got_int) {
|
||||||
/* flush all input */
|
// flush all input
|
||||||
c = inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 0L,
|
c = inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 0L);
|
||||||
typebuf.tb_change_cnt);
|
// If inchar() returns TRUE (script file was active) or we
|
||||||
/*
|
// are inside a mapping, get out of insert mode.
|
||||||
* If inchar() returns TRUE (script file was active) or we
|
// Otherwise we behave like having gotten a CTRL-C.
|
||||||
* are inside a mapping, get out of insert mode.
|
// As a result typing CTRL-C in insert mode will
|
||||||
* Otherwise we behave like having gotten a CTRL-C.
|
// really insert a CTRL-C.
|
||||||
* As a result typing CTRL-C in insert mode will
|
|
||||||
* really insert a CTRL-C.
|
|
||||||
*/
|
|
||||||
if ((c || typebuf.tb_maplen)
|
if ((c || typebuf.tb_maplen)
|
||||||
&& (State & (INSERT + CMDLINE)))
|
&& (State & (INSERT + CMDLINE))) {
|
||||||
c = ESC;
|
c = ESC;
|
||||||
else
|
} else {
|
||||||
c = Ctrl_C;
|
c = Ctrl_C;
|
||||||
flush_buffers(TRUE); /* flush all typeahead */
|
}
|
||||||
|
flush_buffers(true); // flush all typeahead
|
||||||
|
|
||||||
if (advance) {
|
if (advance) {
|
||||||
/* Also record this character, it might be needed to
|
/* Also record this character, it might be needed to
|
||||||
@@ -2075,7 +2072,7 @@ static int vgetorpeek(int advance)
|
|||||||
c = 0;
|
c = 0;
|
||||||
new_wcol = curwin->w_wcol;
|
new_wcol = curwin->w_wcol;
|
||||||
new_wrow = curwin->w_wrow;
|
new_wrow = curwin->w_wrow;
|
||||||
if ( advance
|
if (advance
|
||||||
&& typebuf.tb_len == 1
|
&& typebuf.tb_len == 1
|
||||||
&& typebuf.tb_buf[typebuf.tb_off] == ESC
|
&& typebuf.tb_buf[typebuf.tb_off] == ESC
|
||||||
&& !no_mapping
|
&& !no_mapping
|
||||||
@@ -2084,9 +2081,8 @@ static int vgetorpeek(int advance)
|
|||||||
&& (State & INSERT)
|
&& (State & INSERT)
|
||||||
&& (p_timeout
|
&& (p_timeout
|
||||||
|| (keylen == KEYLEN_PART_KEY && p_ttimeout))
|
|| (keylen == KEYLEN_PART_KEY && p_ttimeout))
|
||||||
&& (c = inchar(typebuf.tb_buf + typebuf.tb_off
|
&& (c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len,
|
||||||
+ typebuf.tb_len, 3, 25L,
|
3, 25L)) == 0) {
|
||||||
typebuf.tb_change_cnt)) == 0) {
|
|
||||||
colnr_T col = 0, vcol;
|
colnr_T col = 0, vcol;
|
||||||
char_u *ptr;
|
char_u *ptr;
|
||||||
|
|
||||||
@@ -2258,6 +2254,11 @@ static int vgetorpeek(int advance)
|
|||||||
/*
|
/*
|
||||||
* get a character: 3. from the user - get it
|
* get a character: 3. from the user - get it
|
||||||
*/
|
*/
|
||||||
|
if (typebuf.tb_len == 0) {
|
||||||
|
// timedout may have been set while waiting for a mapping
|
||||||
|
// that has a <Nop> RHS.
|
||||||
|
timedout = false;
|
||||||
|
}
|
||||||
wait_tb_len = typebuf.tb_len;
|
wait_tb_len = typebuf.tb_len;
|
||||||
c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len,
|
c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len,
|
||||||
typebuf.tb_buflen - typebuf.tb_off - typebuf.tb_len - 1,
|
typebuf.tb_buflen - typebuf.tb_off - typebuf.tb_len - 1,
|
||||||
@@ -2269,7 +2270,7 @@ static int vgetorpeek(int advance)
|
|||||||
? -1L
|
? -1L
|
||||||
: ((keylen == KEYLEN_PART_KEY && p_ttm >= 0)
|
: ((keylen == KEYLEN_PART_KEY && p_ttm >= 0)
|
||||||
? p_ttm
|
? p_ttm
|
||||||
: p_tm)), typebuf.tb_change_cnt);
|
: p_tm)));
|
||||||
|
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
pop_showcmd();
|
pop_showcmd();
|
||||||
@@ -2350,16 +2351,15 @@ static int vgetorpeek(int advance)
|
|||||||
* Return the number of obtained characters.
|
* Return the number of obtained characters.
|
||||||
* Return -1 when end of input script reached.
|
* Return -1 when end of input script reached.
|
||||||
*/
|
*/
|
||||||
int
|
int inchar(
|
||||||
inchar (
|
|
||||||
char_u *buf,
|
char_u *buf,
|
||||||
int maxlen,
|
int maxlen,
|
||||||
long wait_time, /* milli seconds */
|
long wait_time // milli seconds
|
||||||
int tb_change_cnt
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int len = 0; // Init for GCC.
|
int len = 0; // Init for GCC.
|
||||||
int retesc = false; // Return ESC with gotint.
|
int retesc = false; // Return ESC with gotint.
|
||||||
|
const int tb_change_cnt = typebuf.tb_change_cnt;
|
||||||
|
|
||||||
if (wait_time == -1L || wait_time > 100L) {
|
if (wait_time == -1L || wait_time > 100L) {
|
||||||
// flush output before waiting
|
// flush output before waiting
|
||||||
@@ -2430,10 +2430,19 @@ inchar (
|
|||||||
len = os_inchar(buf, maxlen / 3, (int)wait_time, tb_change_cnt);
|
len = os_inchar(buf, maxlen / 3, (int)wait_time, tb_change_cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the typebuf was changed further down, it is like nothing was added by
|
||||||
|
// this call.
|
||||||
if (typebuf_changed(tb_change_cnt)) {
|
if (typebuf_changed(tb_change_cnt)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note the change in the typeahead buffer, this matters for when
|
||||||
|
// vgetorpeek() is called recursively, e.g. using getchar(1) in a timer
|
||||||
|
// function.
|
||||||
|
if (len > 0 && ++typebuf.tb_change_cnt == 0) {
|
||||||
|
typebuf.tb_change_cnt = 1;
|
||||||
|
}
|
||||||
|
|
||||||
return fix_input_buffer(buf, len);
|
return fix_input_buffer(buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -169,5 +169,25 @@ func Test_stop_all_in_callback()
|
|||||||
call assert_equal(0, len(info))
|
call assert_equal(0, len(info))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func FeedAndPeek(timer)
|
||||||
|
call test_feedinput('a')
|
||||||
|
call getchar(1)
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Interrupt(timer)
|
||||||
|
call test_feedinput("\<C-C>")
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_peek_and_get_char()
|
||||||
|
throw 'skipped: Nvim does not support test_feedinput()'
|
||||||
|
if !has('unix') && !has('gui_running')
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
call timer_start(0, 'FeedAndPeek')
|
||||||
|
let intr = timer_start(100, 'Interrupt')
|
||||||
|
let c = getchar()
|
||||||
|
call assert_equal(char2nr('a'), c)
|
||||||
|
call timer_stop(intr)
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ describe('timers', function()
|
|||||||
source([[
|
source([[
|
||||||
func! AddItem(timer)
|
func! AddItem(timer)
|
||||||
call nvim_buf_set_lines(0, 2, 2, v:true, ['ITEM 3'])
|
call nvim_buf_set_lines(0, 2, 2, v:true, ['ITEM 3'])
|
||||||
|
call getchar(1)
|
||||||
redraw
|
redraw
|
||||||
endfunc
|
endfunc
|
||||||
call timer_start(200, 'AddItem')
|
call timer_start(200, 'AddItem')
|
||||||
|
|||||||
Reference in New Issue
Block a user