aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/os/input.c')
-rw-r--r--src/nvim/os/input.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c
index cddc28fac9..2ae4558f3d 100644
--- a/src/nvim/os/input.c
+++ b/src/nvim/os/input.c
@@ -184,18 +184,24 @@ size_t input_enqueue(String keys)
while (rbuffer_available(input_buffer) >= 6 && ptr < end) {
uint8_t buf[6] = {0};
- int new_size = trans_special((uint8_t **)&ptr, buf, false);
+ unsigned int new_size = trans_special((uint8_t **)&ptr, buf, false);
if (!new_size) {
+ if (*ptr == '<') {
+ // Invalid key sequence, skip until the next '>' or until *end
+ do {
+ ptr++;
+ } while (ptr < end && *ptr != '>');
+ ptr++;
+ continue;
+ }
// copy the character unmodified
*buf = (uint8_t)*ptr++;
new_size = 1;
}
new_size = handle_mouse_event(&ptr, buf, new_size);
- // TODO(tarruda): Don't produce past unclosed '<' characters, except if
- // there's a lot of characters after the '<'
- rbuffer_write(input_buffer, (char *)buf, (size_t)new_size);
+ rbuffer_write(input_buffer, (char *)buf, new_size);
}
size_t rv = (size_t)(ptr - keys.data);
@@ -205,7 +211,8 @@ size_t input_enqueue(String keys)
// Mouse event handling code(Extract row/col if available and detect multiple
// clicks)
-static int handle_mouse_event(char **ptr, uint8_t *buf, int bufsize)
+static unsigned int handle_mouse_event(char **ptr, uint8_t *buf,
+ unsigned int bufsize)
{
int mouse_code = 0;
@@ -216,7 +223,8 @@ static int handle_mouse_event(char **ptr, uint8_t *buf, int bufsize)
mouse_code = buf[5];
}
- if (mouse_code < KE_LEFTMOUSE || mouse_code > KE_RIGHTRELEASE) {
+ if (!((mouse_code >= KE_LEFTMOUSE && mouse_code <= KE_RIGHTRELEASE)
+ || (mouse_code >= KE_MOUSEDOWN && mouse_code <= KE_MOUSERIGHT))) {
return bufsize;
}
@@ -225,7 +233,7 @@ static int handle_mouse_event(char **ptr, uint8_t *buf, int bufsize)
// find mouse coordinates, and it would be too expensive to refactor this
// now.
int col, row, advance;
- if (sscanf(*ptr, "<%d,%d>%n", &col, &row, &advance)) {
+ if (sscanf(*ptr, "<%d,%d>%n", &col, &row, &advance) != EOF && advance) {
if (col >= 0 && row >= 0) {
mouse_row = row;
mouse_col = col;