1
0
forked from aniani/vim

patch 8.2.3727: in a gnome terminal keys are recognized as mouse events

Problem:    In a gnome terminal keys are recognized as mouse events.
Solution:   Only recognize DEC mouse events when four numbers are following.
            (closes #9256)
This commit is contained in:
Bram Moolenaar
2021-12-03 13:20:29 +00:00
parent c903695be5
commit c14b57c079
3 changed files with 65 additions and 6 deletions

View File

@@ -5412,6 +5412,8 @@ check_termcode(
if (STRNCMP(termcodes[idx].code, tp,
(size_t)(slen > len ? len : slen)) == 0)
{
int looks_like_mouse_start = FALSE;
if (len < slen) // got a partial sequence
return -1; // need to get more chars
@@ -5434,15 +5436,48 @@ check_termcode(
}
}
// The mouse termcode "ESC [" is also the prefix of
// "ESC [ I" (focus gained). Only use it when there is
// no other match. Do use it when a digit is following to
// avoid waiting for more bytes.
if (slen == 2 && len > 2
&& termcodes[idx].code[0] == ESC
&& termcodes[idx].code[1] == '['
&& !isdigit(tp[2]))
&& termcodes[idx].code[1] == '[')
{
// The mouse termcode "ESC [" is also the prefix of
// "ESC [ I" (focus gained) and other keys. Check some
// more bytes to find out.
if (!isdigit(tp[2]))
{
// ESC [ without number following: Only use it when
// there is no other match.
looks_like_mouse_start = TRUE;
}
else if (termcodes[idx].name[0] == KS_DEC_MOUSE)
{
char_u *nr = tp + 2;
int count = 0;
// If a digit is following it could be a key with
// modifier, e.g., ESC [ 1;2P. Can be confused
// with DEC_MOUSE, which requires four numbers
// following. If not then it can't be a DEC_MOUSE
// code.
for (;;)
{
++count;
(void)getdigits(&nr);
if (nr >= tp + len)
return -1; // partial sequence
if (*nr != ';')
break;
++nr;
if (nr >= tp + len)
return -1; // partial sequence
}
if (count < 4)
continue; // no match
}
}
if (looks_like_mouse_start)
{
// Only use it when there is no other match.
if (mouse_index_found < 0)
mouse_index_found = idx;
}