Generate MouseUp events (#1968)

* Remove redundant import

* Generate a MouseUp event when dragging stops

* Update CHANGELOG.md

* Ensure button is propagated through to artificial MouseUp event
This commit is contained in:
darrenburns 2023-03-09 11:56:38 +00:00 committed by GitHub
parent 72e32f2206
commit f929e133b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View file

@ -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

View file

@ -6,6 +6,7 @@ from typing import TYPE_CHECKING
from . import _clock, events
from ._types import MessageTarget
from .events import MouseUp
if TYPE_CHECKING:
from rich.console import Console
@ -26,6 +27,8 @@ class Driver(ABC):
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:
@ -41,6 +44,29 @@ class Driver(ABC):
"""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)

View file

@ -17,7 +17,6 @@ if TYPE_CHECKING:
import rich.repr
from .. import events, log
from .._profile import timer
from .._types import MessageTarget
from .._xterm_parser import XTermParser
from ..driver import Driver