Skip to content

Commit afd5465

Browse files
authored
Merge pull request #3647 from EricWF/fix-terminal-movements
Fix erroneous ButtonDown mouse event reporting.
2 parents df377f1 + 53af952 commit afd5465

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
579579
- Fixed CSS watcher crash if file becomes unreadable (even temporarily) https://github.com/Textualize/textual/pull/4079
580580
- Fixed display of keys when used in conjunction with other keys https://github.com/Textualize/textual/pull/3050
581581
- Fixed double detection of <kbd>Escape</kbd> on Windows https://github.com/Textualize/textual/issues/4038
582+
- Fixed erroneous mouse 'ButtonDown' reporting for mouse movement when any-event mode is enabled in xterm. https://github.com/Textualize/textual/pull/3647
583+
582584

583585
## [0.47.1] - 2024-01-05
584586

src/textual/_xterm_parser.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,14 @@ def parse_mouse_code(self, code: str) -> events.Event | None:
7777
)
7878
button = 0
7979
else:
80-
if buttons & 32:
80+
button = (buttons + 1) & 3
81+
# XTerm events for mouse movement can look like mouse button down events. But if there is no key pressed,
82+
# it's a mouse move event.
83+
if buttons & 32 or button == 0:
8184
event_class = events.MouseMove
8285
else:
8386
event_class = events.MouseDown if state == "M" else events.MouseUp
8487

85-
button = (buttons + 1) & 3
86-
8788
event = event_class(
8889
x,
8990
y,

tests/test_xterm_parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ def test_mouse_click(parser, sequence, event_type, shift, meta):
218218
("\x1b[<35;15;38M", False, False, 0), # Basic cursor movement
219219
("\x1b[<39;15;38M", True, False, 0), # Shift held down
220220
("\x1b[<43;15;38M", False, True, 0), # Meta held down
221+
("\x1b[<3;15;38M", False, False, 0),
221222
],
222223
)
223224
def test_mouse_move(parser, sequence, shift, meta, button):

0 commit comments

Comments
 (0)