-
Couldn't load subscription status.
- Fork 585
feat: Control and listen to selection/caret changes in TextField
#5725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've reviewed this pull request using the Sourcery rules engine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds text selection control and monitoring capabilities to TextField and CupertinoTextField components. Users can now programmatically control text selection/caret position and listen to selection change events through a new on_selection_change callback.
Key Changes
- Introduced
TextSelectionclass withbase_offset/extent_offsetproperties to represent text selections - Added
on_selection_changeevent handler to TextField/CupertinoTextField for monitoring selection changes - Added
selectionproperty to TextField for programmatic control of text selection and caret position
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/python/packages/flet/src/flet/controls/material/textfield.py | Added selection property and on_selection_change event handler to TextField |
| sdk/python/packages/flet/src/flet/controls/material/form_field_control.py | Added documentation for the focus() method |
| sdk/python/packages/flet/src/flet/controls/core/text.py | Refactored TextSelection to use base_offset/extent_offset as required fields with computed properties; updated TextSelectionChangeEvent structure |
| sdk/python/packages/flet/mkdocs.yml | Enabled show_labels in documentation configuration |
| sdk/python/packages/flet/docs/controls/textfield.md | Added example demonstrating selection change handling |
| sdk/python/packages/flet/docs/controls/cupertinotextfield.md | Added selection change and background image examples |
| sdk/python/packages/flet-map/src/flet_map/marker_layer.py | Fixed broken reference link in documentation |
| sdk/python/examples/controls/text_field/selection_change.py | New example demonstrating selection monitoring and control |
| sdk/python/examples/controls/cupertino_text_field/selection_change.py | New example for CupertinoTextField selection handling |
| sdk/python/examples/controls/cupertino_text_field/label_focus.py | Removed obsolete example file |
| packages/flet/lib/src/utils/text.dart | Added TextSelection parsing utilities and refactored switch statements to map lookups |
| packages/flet/lib/src/controls/textfield.dart | Implemented selection change tracking and programmatic selection control |
| packages/flet/lib/src/controls/text.dart | Updated event field name from "text" to "selected_text" |
| packages/flet/lib/src/controls/cupertino_textfield.dart | Implemented selection change tracking for CupertinoTextField |
| packages/flet/lib/src/controls/base_controls.dart | Refactored _sizedControl to properly handle AnimatedContainer with dimensions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
sdk/python/packages/flet/src/flet/controls/material/textfield.py
Outdated
Show resolved
Hide resolved
sdk/python/examples/controls/cupertino_text_field/selection_change.py
Outdated
Show resolved
Hide resolved
Deploying flet-docs with
|
| Latest commit: |
fbdb83f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e0a3286e.flet-docs.pages.dev |
| Branch Preview URL: | https://textfield-text-selection.flet-docs.pages.dev |
Fix #1005
Fix #1742
Fix #2916
Fix #5467
Fix #3335
Fix #5708
Example
Summary by Sourcery
Implement text selection and caret control in text fields across Dart and Python SDK, including new event triggers, property parsing, and updated utilities, plus docs and examples.
New Features:
selectionproperty andon_selection_changeevent to TextField and CupertinoTextField for programmatic control and listening to selection/caret changesEnhancements:
start,end,is_valid,is_collapsed,is_normalized, etc.) and implement parsing/serialization in DartgetTextStyle,getFontWeight) to use lookup mapsDocumentation:
show_labelsin mkdocs configuration