Skip to content

Commit

Permalink
Implement copy and cut behavior for TextInput
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Mar 10, 2021
1 parent 21971e0 commit 17dcfa8
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions native/src/widget/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,46 @@ where
self.state.cursor.move_to(self.value.len());
}
}
keyboard::KeyCode::C
if self
.state
.keyboard_modifiers
.is_command_pressed() =>
{
match self.state.cursor.selection(&self.value) {
Some((start, end)) => {
clipboard.write(
self.value.select(start, end).to_string(),
);
}
None => {}
}
}
keyboard::KeyCode::X
if self
.state
.keyboard_modifiers
.is_command_pressed() =>
{
match self.state.cursor.selection(&self.value) {
Some((start, end)) => {
clipboard.write(
self.value.select(start, end).to_string(),
);
}
None => {}
}

let mut editor = Editor::new(
&mut self.value,
&mut self.state.cursor,
);

editor.delete();

let message = (self.on_change)(editor.contents());
messages.push(message);
}
keyboard::KeyCode::V => {
if self.state.keyboard_modifiers.is_command_pressed() {
let content = match self.state.is_pasting.take() {
Expand Down

0 comments on commit 17dcfa8

Please sign in to comment.