diff options
author | 2023-09-16 15:40:16 +0200 | |
---|---|---|
committer | 2023-09-16 15:40:16 +0200 | |
commit | d051f21597bb333ac10183aaa3214a292e9aa365 (patch) | |
tree | 0735e31bae1fefcf004ebba199bd5ec759040605 /widget/src/text_editor.rs | |
parent | c6d0443627c22dcf1576303e5a426aa3622f1b7d (diff) | |
download | iced-d051f21597bb333ac10183aaa3214a292e9aa365.tar.gz iced-d051f21597bb333ac10183aaa3214a292e9aa365.tar.bz2 iced-d051f21597bb333ac10183aaa3214a292e9aa365.zip |
Implement `Copy` and `Paste` actions for `text::Editor`
Diffstat (limited to 'widget/src/text_editor.rs')
-rw-r--r-- | widget/src/text_editor.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index ec7a6d1d..0bb6b7d3 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -12,6 +12,7 @@ use crate::core::{ }; use std::cell::RefCell; +use std::sync::Arc; pub use crate::style::text_editor::{Appearance, StyleSheet}; pub use text::editor::{Action, Motion}; @@ -253,10 +254,14 @@ where Update::Edit(action) => { shell.publish(on_edit(action)); } - Update::Copy => todo!(), + Update::Copy => { + if let Some(selection) = self.content.selection() { + clipboard.write(selection); + } + } Update::Paste => { - if let Some(_contents) = clipboard.read() { - todo!() + if let Some(contents) = clipboard.read() { + shell.publish(on_edit(Action::Paste(Arc::new(contents)))); } } } |