From f19e8f72c854b35f95de44fa9558ae200a6409b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dtalo=20Dell=20Areti?= Date: Thu, 19 Feb 2026 13:18:02 -0300 Subject: [PATCH] feat(text_input): add select_range method and Task function --- src/widget/text_input/input.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/widget/text_input/input.rs b/src/widget/text_input/input.rs index 3960cee1..43db6a4d 100644 --- a/src/widget/text_input/input.rs +++ b/src/widget/text_input/input.rs @@ -1125,6 +1125,14 @@ pub fn select_all(id: Id) -> Task { task::effect(Action::widget(operation::text_input::select_all(id))) } +/// Produces a [`Task`] that selects a range of the content of the [`TextInput`] with the given +/// [`Id`]. +pub fn select_range(id: Id, start: usize, end: usize) -> Task { + task::effect(Action::widget(operation::text_input::select_range( + id, start, end, + ))) +} + /// Computes the layout of a [`TextInput`]. #[allow(clippy::cast_precision_loss)] #[allow(clippy::too_many_arguments)] @@ -2782,6 +2790,12 @@ impl State { self.cursor.select_range(0, usize::MAX); } + /// Selects a range of the content of the [`TextInput`]. + #[inline] + pub fn select_range(&mut self, start: usize, end: usize) { + self.cursor.select_range(start, end); + } + pub(super) fn setting_selection(&mut self, value: &Value, bounds: Rectangle, target: f32) { let position = if target > 0.0 { find_cursor_position(bounds, value, self, target) @@ -2842,8 +2856,9 @@ impl operation::TextInput for State { todo!() } + #[inline] fn select_range(&mut self, start: usize, end: usize) { - todo!() + Self::select_range(self, start, end); } }