Skip to content

Fix double-click and triple-click selection behavior - #6697

Open
nicholasirwin wants to merge 1 commit into
Textualize:mainfrom
nicholasirwin:fix-6633-double-triple-click-selection
Open

Fix double-click and triple-click selection behavior#6697
nicholasirwin wants to merge 1 commit into
Textualize:mainfrom
nicholasirwin:fix-6633-double-triple-click-selection

Conversation

@nicholasirwin

Copy link
Copy Markdown

Description

This PR changes double-click and triple-click selection in Textual so they select words and paragraphs instead of the whole widget.

  • Double-click now selects the word at the click position (including URLs and words with apostrophes/hyphens).
  • Triple-click now selects the paragraph at the click position.
  • Both fall back to the previous behavior (select widget / select container) when the click cannot be mapped to text content.

Changes

  • Added textual._word_segmentation module with an optional regex dependency and a re fallback.
  • Added textual._text_selection helpers for word/paragraph segmentation with CRLF-aware offset math.
  • Added Widget.get_selectable_text(), Widget.get_word_selection(), Widget.get_paragraph_selection(), Widget.text_select_word(), and Widget.text_select_paragraph().
  • Updated Widget._on_click() to use the new selection methods.
  • Refactored Widget.get_selection() to share text extraction logic with get_selectable_text().
  • Fixed stale _select_state by clearing it when mutating Screen.selections directly.
  • Preserved the container-select fallback for triple-click on non-text widgets.

Test plan

pytest tests/test_selection.py tests/test_text_selection.py

Fixes #6633

Double-click now selects a word (or URL), and triple-click selects a
paragraph (or the widget/container fallback when text is unavailable).

Changes:
- Added textual/_word_segmentation.py with optional regex dependency
- Added textual/_text_selection.py helpers for word/paragraph selection
- Added Widget.get_selectable_text(), get_word_selection(),
  get_paragraph_selection(), text_select_word(), text_select_paragraph()
- Updated Widget._on_click() to use word/paragraph selection
- Fixed CRLF line-ending offset math
- Preserved container-select fallback for triple-click
- Cleared _select_state when mutating selections directly

Fixes Textualize#6633

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Double-click and triple-click selection are unintuitive

1 participant