From b3adeb7d21c3a1cc8f5f9acc08c8205d118403a9 Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Sat, 29 Mar 2025 21:28:46 +0000 Subject: [PATCH] fix: handle negative mouse coordinates It is possible that terminals will report negative mouse coordinates when using SGR-Pixels (1016). While this arguably violates the standard for CSI sequences (see https://github.com/Textualize/textual/issues/5559), perhaps Textual should be more resilient to handle these sequences. --- src/textual/_xterm_parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/textual/_xterm_parser.py b/src/textual/_xterm_parser.py index 4cc21fecc5..a81e35983b 100644 --- a/src/textual/_xterm_parser.py +++ b/src/textual/_xterm_parser.py @@ -18,7 +18,7 @@ # to be unsuccessful? _MAX_SEQUENCE_SEARCH_THRESHOLD = 32 -_re_mouse_event = re.compile("^" + re.escape("\x1b[") + r"(\d+);(?P\d)\$y" ) @@ -50,7 +50,7 @@ class XTermParser(Parser[Message]): - _re_sgr_mouse = re.compile(r"\x1b\[<(\d+);(\d+);(\d+)([Mm])") + _re_sgr_mouse = re.compile(r"\x1b\[<(\d+);(-?\d+);(-?\d+)([Mm])") def __init__(self, debug: bool = False) -> None: self.last_x = 0.0