aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan Edmund Lazo <janedmundlazo@hotmail.com>2018-08-22 15:05:09 -0400
committerJan Edmund Lazo <janedmundlazo@hotmail.com>2018-09-04 10:00:17 -0400
commitc87510b0e803f44ca06b16f831d6fa5c196da1de (patch)
tree6528cd65259f9bdd2be640bb5725836837621c37 /src
parent90519107f2423f0ef71d2db821af32a3e33e23d6 (diff)
downloadrneovim-c87510b0e803f44ca06b16f831d6fa5c196da1de.tar.gz
rneovim-c87510b0e803f44ca06b16f831d6fa5c196da1de.tar.bz2
rneovim-c87510b0e803f44ca06b16f831d6fa5c196da1de.zip
vim-patch:8.0.1020: when a timer calls getchar(1) input is overwritten
Problem: When a timer calls getchar(1) input is overwritten. Solution: Increment tb_change_cnt in inchar(). (closes vim/vim#1940) https://github.com/vim/vim/commit/0f0f230012f5a9beb6876158a17b432534836c6f
Diffstat (limited to 'src')
-rw-r--r--src/nvim/getchar.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index df185f1a5b..17168e7ca2 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -434,8 +434,7 @@ void flush_buffers(int flush_typeahead)
* of an escape sequence.
* 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,
- typebuf.tb_change_cnt) != 0)
+ while (inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 10L) != 0)
;
typebuf.tb_off = MAXMAPLEN;
typebuf.tb_len = 0;
@@ -1698,8 +1697,7 @@ static int vgetorpeek(int advance)
keylen = 0;
if (got_int) {
/* flush all input */
- c = inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 0L,
- typebuf.tb_change_cnt);
+ c = inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 0L);
/*
* If inchar() returns TRUE (script file was active) or we
* are inside a mapping, get out of insert mode.
@@ -2085,8 +2083,7 @@ static int vgetorpeek(int advance)
&& (p_timeout
|| (keylen == KEYLEN_PART_KEY && p_ttimeout))
&& (c = inchar(typebuf.tb_buf + typebuf.tb_off
- + typebuf.tb_len, 3, 25L,
- typebuf.tb_change_cnt)) == 0) {
+ + typebuf.tb_len, 3, 25L)) == 0) {
colnr_T col = 0, vcol;
char_u *ptr;
@@ -2269,7 +2266,7 @@ static int vgetorpeek(int advance)
? -1L
: ((keylen == KEYLEN_PART_KEY && p_ttm >= 0)
? p_ttm
- : p_tm)), typebuf.tb_change_cnt);
+ : p_tm)));
if (i != 0)
pop_showcmd();
@@ -2350,16 +2347,15 @@ static int vgetorpeek(int advance)
* Return the number of obtained characters.
* Return -1 when end of input script reached.
*/
-int
-inchar (
+int inchar(
char_u *buf,
int maxlen,
- long wait_time, /* milli seconds */
- int tb_change_cnt
+ long wait_time // milli seconds
)
{
int len = 0; // Init for GCC.
int retesc = false; // Return ESC with gotint.
+ const int tb_change_cnt = typebuf.tb_change_cnt;
if (wait_time == -1L || wait_time > 100L) {
// flush output before waiting
@@ -2430,10 +2426,19 @@ inchar (
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)) {
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);
}