summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-03-10 01:59:20 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-03-10 01:59:20 +0100
commit17dcfa8faf68afe3cbad1151f41eb35230ef83e1 (patch)
treecc48512ff63a54d27d826796b9212260b0b0aafa /native
parent21971e0037c2ddcb96fd48ea96332445de4137bb (diff)
downloadiced-17dcfa8faf68afe3cbad1151f41eb35230ef83e1.tar.gz
iced-17dcfa8faf68afe3cbad1151f41eb35230ef83e1.tar.bz2
iced-17dcfa8faf68afe3cbad1151f41eb35230ef83e1.zip
Implement copy and cut behavior for `TextInput`
Diffstat (limited to 'native')
-rw-r--r--native/src/widget/text_input.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs
index 400cae2a..de6032b7 100644
--- a/native/src/widget/text_input.rs
+++ b/native/src/widget/text_input.rs
@@ -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() {