Skip to content

Commit

Permalink
Merge pull request #776 from AldoMX/master
Browse files Browse the repository at this point in the history
Added `select_all` method to `TextInput`.
  • Loading branch information
hecrj authored Jul 22, 2021
2 parents f076649 + 72d5d9b commit 587dbbc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion examples/todos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,11 @@ 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(),
};
}
Expand Down
5 changes: 5 additions & 0 deletions native/src/widget/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,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
Expand Down
5 changes: 5 additions & 0 deletions web/src/widget/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,9 @@ impl State {
// TODO
Self::default()
}

/// Selects all the content of the [`TextInput`].
pub fn select_all(&mut self) {
// TODO
}
}

0 comments on commit 587dbbc

Please sign in to comment.