diff --git a/src/widget/text_input/input.rs b/src/widget/text_input/input.rs index 7dd92e12..349daee0 100644 --- a/src/widget/text_input/input.rs +++ b/src/widget/text_input/input.rs @@ -1122,6 +1122,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)] @@ -2750,6 +2758,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) @@ -2805,6 +2819,11 @@ impl operation::TextInput for State { fn select_all(&mut self) { Self::select_all(self); } + + #[inline] + fn select_range(&mut self, start: usize, end: usize) { + Self::select_range(self, start, end); + } } #[inline(never)]