From 57247106b95acb120381305cbe1ab4077b17651f Mon Sep 17 00:00:00 2001 From: Aldo Fregoso Date: Sat, 13 Mar 2021 14:50:59 -0600 Subject: [PATCH 1/3] Added `select_all` method to `TextInput`. --- examples/todos/src/main.rs | 4 +++- native/src/widget/text_input.rs | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 7186b95073..ee0022d541 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -265,8 +265,10 @@ impl Task { self.completed = completed; } TaskMessage::Edit => { + let mut text_input = text_input::State::focused(); + text_input.select_all(); self.state = TaskState::Editing { - text_input: text_input::State::focused(), + text_input, delete_button: button::State::new(), }; } diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index de6032b77a..2a0913f311 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -792,6 +792,11 @@ impl State { pub fn move_cursor_to(&mut self, position: usize) { self.cursor.move_to(position); } + + /// Selects all the content of the [`TextInput`]. + pub fn select_all(&mut self) { + self.cursor.select_range(0, usize::MAX); + } } // TODO: Reduce allocations From 29cc840cfa129a5ee3ecd1befe6e0fe85cb0e2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 22 Jul 2021 20:32:54 +0700 Subject: [PATCH 2/3] Add empty `select_all` implementation for `TextInput` in `iced_web` --- web/src/widget/text_input.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web/src/widget/text_input.rs b/web/src/widget/text_input.rs index bc2048a8d3..d61ee2fd83 100644 --- a/web/src/widget/text_input.rs +++ b/web/src/widget/text_input.rs @@ -232,4 +232,9 @@ impl State { // TODO Self::default() } + + /// Selects all the content of the [`TextInput`]. + pub fn select_all(&mut self) { + // TODO + } } From 72d5d9b4bd03f6596369360018ee101a4a3053ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 22 Jul 2021 20:37:12 +0700 Subject: [PATCH 3/3] Add newline to `todos` example ... just for readability --- examples/todos/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index ee0022d541..9741547550 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -267,6 +267,7 @@ impl Task { TaskMessage::Edit => { let mut text_input = text_input::State::focused(); text_input.select_all(); + self.state = TaskState::Editing { text_input, delete_button: button::State::new(),