Skip to content

Commit 63ef97d

Browse files
committed
allow select
1 parent 8fdb3ee commit 63ef97d

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2323
- Added `Widget.scrollable_container` property
2424
- Added `Widget.select_all`
2525
- Added `Region.bottom_right_inclusive`
26+
- Added double click to select, triple click to select all in container
27+
- Added arbitrary text selection
28+
- Added Widget.ALLOW_SELECT classvar for a per-widget switch to disable text selection
29+
- Added Widget.allow_select method for programmatic control of text selection
30+
- Added App.ALLOW_SELECT for a global switch to disable text selection
2631

2732
### Fixed
2833

src/textual/app.py

+6
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,12 @@ class MyApp(App[None]):
396396
Setting to `None` or `""` disables auto focus.
397397
"""
398398

399+
ALLOW_SELECT: ClassVar[bool] = True
400+
"""A switch to toggle arbitrary text selection for the app.
401+
402+
Note that this doesn't apply to Input and TextArea which have builtin support for selection.
403+
"""
404+
399405
_BASE_PATH: str | None = None
400406
CSS_PATH: ClassVar[CSSPathType | None] = None
401407
"""File paths to load CSS from."""

src/textual/screen.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,11 @@ def is_active(self) -> bool:
511511
except Exception:
512512
return False
513513

514+
@property
515+
def allow_select(self) -> bool:
516+
"""Check if this widget permits text selection."""
517+
return self.ALLOW_SELECT
518+
514519
def render(self) -> RenderableType:
515520
"""Render method inherited from widget, used to render the screen's background.
516521
@@ -1520,7 +1525,12 @@ def _forward_event(self, event: events.Event) -> None:
15201525
select_widget, select_offset = self.get_widget_and_offset_at(
15211526
event.screen_x, event.screen_y
15221527
)
1523-
if select_widget is not None and select_widget.allow_select:
1528+
if (
1529+
select_widget is not None
1530+
and select_widget.allow_select
1531+
and self.screen.allow_select
1532+
and self.app.ALLOW_SELECT
1533+
):
15241534
self._selecting = True
15251535
if select_widget is not None and select_offset is not None:
15261536
self._select_start = (

0 commit comments

Comments
 (0)