Skip to content

Commit

Permalink
added box select
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jan 7, 2025
1 parent df2b3a3 commit 51905de
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/textual/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ class Screen(Generic[ScreenResultType], Widget):
_selecting = var(False)
"""Indicates mouse selection is in progress."""

_box_select = var(False)
"""Should text selection be limited to a box?"""

_select_start: Reactive[tuple[Widget, Offset, Offset] | None] = Reactive(None)
"""Tuple of (widget, screen offset, text offset) where selection started."""
_select_end: Reactive[tuple[Widget, Offset, Offset] | None] = Reactive(None)
Expand Down Expand Up @@ -1491,6 +1494,7 @@ def _forward_event(self, event: events.Event) -> None:
self._handle_mouse_move(event)

if self._selecting:
self._box_select = event.shift
select_widget, select_offset = self.get_widget_and_offset_at(
event.x, event.y
)
Expand Down Expand Up @@ -1521,6 +1525,7 @@ def _forward_event(self, event: events.Event) -> None:
self._selecting = False

elif isinstance(event, events.MouseDown) and not self.app.mouse_captured:
self._box_select = event.shift
self._mouse_down_offset = event.screen_offset
select_widget, select_offset = self.get_widget_and_offset_at(
event.screen_x, event.screen_y
Expand Down Expand Up @@ -1603,7 +1608,7 @@ def _watch__select_end(
select_regions: list[Region] = []
start_region = start_widget.content_region
end_region = end_widget.content_region
if end_region.y <= start_region.bottom:
if end_region.y <= start_region.bottom or self._box_select:
select_regions.append(Region.union(start_region, end_region))
else:
container_region = Region.from_union(
Expand Down

0 comments on commit 51905de

Please sign in to comment.