diff --git a/CHANGELOG.md b/CHANGELOG.md index 2533447e73..cf6b986492 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed issue with the "transparent" CSS value not being transparent when set using python https://github.com/Textualize/textual/pull/5890 - Fixed issue with pushing screens when Input has mouse captured https://github.com/Textualize/textual/pull/5900 +- Implemented workaround for Ghostty bug which produces negative mouse coordinates https://github.com/Textualize/textual/pull/5926 ## Changed diff --git a/src/textual/_xterm_parser.py b/src/textual/_xterm_parser.py index ed4163fec6..431a4866e7 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 @@ -78,6 +78,9 @@ def parse_mouse_code(self, code: str) -> Message | None: buttons = int(_buttons) x = float(int(_x) - 1) y = float(int(_y) - 1) + if x < 0 or y < 0: + # TODO: Workaround for Ghostty erroneous negative coordinate bug + return None if ( self.mouse_pixels and self.terminal_pixel_size is not None