Skip to content

Commit

Permalink
Generate MouseUp events (#1968)
Browse files Browse the repository at this point in the history
* Remove redundant import

* Generate a MouseUp event when dragging stops

* Update CHANGELOG.md

* Ensure button is propagated through to artificial MouseUp event
  • Loading branch information
darrenburns authored Mar 9, 2023
1 parent 72e32f2 commit f929e13
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Fixed bug that prevented pilot from pressing some keys https://github.com/Textualize/textual/issues/1815
- DataTable race condition that caused crash https://github.com/Textualize/textual/pull/1962
- Fixed scrollbar getting "stuck" to cursor when cursor leaves window during drag https://github.com/Textualize/textual/pull/1968
- DataTable crash when enter pressed when table is empty https://github.com/Textualize/textual/pull/1973

## [0.13.0] - 2023-03-02
Expand Down
26 changes: 26 additions & 0 deletions src/textual/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from . import _clock, events
from ._types import MessageTarget
from .events import MouseUp

if TYPE_CHECKING:
from rich.console import Console
Expand All @@ -26,6 +27,8 @@ def __init__(
self._size = size
self._loop = asyncio.get_running_loop()
self._mouse_down_time = _clock.get_time_no_wait()
self._dragging = False
self._dragging_button = None

@property
def is_headless(self) -> bool:
Expand All @@ -41,6 +44,29 @@ def process_event(self, event: events.Event) -> None:
"""Performs some additional processing of events."""
if isinstance(event, events.MouseDown):
self._mouse_down_time = event.time
elif isinstance(event, events.MouseMove):
if event.button and not self._dragging:
self._dragging = True
self._dragging_button = event.button
elif self._dragging and self._dragging_button != event.button:
# Artificially generate a MouseUp event when we stop "dragging"
self.send_event(
MouseUp(
x=event.x,
y=event.y,
delta_x=event.delta_x,
delta_y=event.delta_y,
button=self._dragging_button,
shift=event.shift,
meta=event.meta,
ctrl=event.ctrl,
screen_x=event.screen_x,
screen_y=event.screen_y,
style=event.style,
)
)
self._dragging = False
self._dragging_button = None

self.send_event(event)

Expand Down
1 change: 0 additions & 1 deletion src/textual/drivers/linux_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import rich.repr

from .. import events, log
from .._profile import timer
from .._types import MessageTarget
from .._xterm_parser import XTermParser
from ..driver import Driver
Expand Down

0 comments on commit f929e13

Please sign in to comment.