comparison src/term.c @ 26392:201243ceaa18 v8.2.3727

patch 8.2.3727: in a gnome terminal keys are recognized as mouse events Commit: https://github.com/vim/vim/commit/c14b57c0795671bafca14433bc376acfe6135a3a Author: Bram Moolenaar <Bram@vim.org> Date: Fri Dec 3 13:20:29 2021 +0000 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)
author Bram Moolenaar <Bram@vim.org>
date Fri, 03 Dec 2021 14:30:04 +0100
parents a2e6da79274d
children d26bab4f6aca
comparison
equal deleted inserted replaced
26391:6e87e34e4e35 26392:201243ceaa18
5410 if (cpo_koffset && offset && len < slen) 5410 if (cpo_koffset && offset && len < slen)
5411 continue; 5411 continue;
5412 if (STRNCMP(termcodes[idx].code, tp, 5412 if (STRNCMP(termcodes[idx].code, tp,
5413 (size_t)(slen > len ? len : slen)) == 0) 5413 (size_t)(slen > len ? len : slen)) == 0)
5414 { 5414 {
5415 int looks_like_mouse_start = FALSE;
5416
5415 if (len < slen) // got a partial sequence 5417 if (len < slen) // got a partial sequence
5416 return -1; // need to get more chars 5418 return -1; // need to get more chars
5417 5419
5418 /* 5420 /*
5419 * When found a keypad key, check if there is another key 5421 * When found a keypad key, check if there is another key
5432 idx = j; 5434 idx = j;
5433 break; 5435 break;
5434 } 5436 }
5435 } 5437 }
5436 5438
5437 // The mouse termcode "ESC [" is also the prefix of
5438 // "ESC [ I" (focus gained). Only use it when there is
5439 // no other match. Do use it when a digit is following to
5440 // avoid waiting for more bytes.
5441 if (slen == 2 && len > 2 5439 if (slen == 2 && len > 2
5442 && termcodes[idx].code[0] == ESC 5440 && termcodes[idx].code[0] == ESC
5443 && termcodes[idx].code[1] == '[' 5441 && termcodes[idx].code[1] == '[')
5444 && !isdigit(tp[2]))
5445 { 5442 {
5443 // The mouse termcode "ESC [" is also the prefix of
5444 // "ESC [ I" (focus gained) and other keys. Check some
5445 // more bytes to find out.
5446 if (!isdigit(tp[2]))
5447 {
5448 // ESC [ without number following: Only use it when
5449 // there is no other match.
5450 looks_like_mouse_start = TRUE;
5451 }
5452 else if (termcodes[idx].name[0] == KS_DEC_MOUSE)
5453 {
5454 char_u *nr = tp + 2;
5455 int count = 0;
5456
5457 // If a digit is following it could be a key with
5458 // modifier, e.g., ESC [ 1;2P. Can be confused
5459 // with DEC_MOUSE, which requires four numbers
5460 // following. If not then it can't be a DEC_MOUSE
5461 // code.
5462 for (;;)
5463 {
5464 ++count;
5465 (void)getdigits(&nr);
5466 if (nr >= tp + len)
5467 return -1; // partial sequence
5468 if (*nr != ';')
5469 break;
5470 ++nr;
5471 if (nr >= tp + len)
5472 return -1; // partial sequence
5473 }
5474 if (count < 4)
5475 continue; // no match
5476 }
5477 }
5478 if (looks_like_mouse_start)
5479 {
5480 // Only use it when there is no other match.
5446 if (mouse_index_found < 0) 5481 if (mouse_index_found < 0)
5447 mouse_index_found = idx; 5482 mouse_index_found = idx;
5448 } 5483 }
5449 else 5484 else
5450 { 5485 {