Skip to content

Commit

Permalink
Added select_all method to TextInput.
Browse files Browse the repository at this point in the history
  • Loading branch information
AldoMX committed Mar 13, 2021
1 parent c1f70f1 commit 5724710
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion examples/todos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
}
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 @@ -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
Expand Down

2 comments on commit 5724710

@foodornt
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't compile

@hecrj
Copy link
Member

@hecrj hecrj commented on 5724710 Aug 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@foodornt This was fixed in 29cc840.

Please sign in to comment.