Fix double-click and triple-click selection behavior - #6697
Open
nicholasirwin wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR changes double-click and triple-click selection in Textual so they select words and paragraphs instead of the whole widget.
Changes
textual._word_segmentationmodule with an optionalregexdependency and arefallback.textual._text_selectionhelpers for word/paragraph segmentation with CRLF-aware offset math.Widget.get_selectable_text(),Widget.get_word_selection(),Widget.get_paragraph_selection(),Widget.text_select_word(), andWidget.text_select_paragraph().Widget._on_click()to use the new selection methods.Widget.get_selection()to share text extraction logic withget_selectable_text()._select_stateby clearing it when mutatingScreen.selectionsdirectly.Test plan
Fixes #6633