summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2022-07-13 18:52:24 +0200
committerLibravatar GitHub <noreply@github.com>2022-07-13 18:52:24 +0200
commite187d6ce7bd5e984950fa3e8aa36ccb1337edc9c (patch)
tree158e999eaf585c3c440cdec51e84b0a96de747fd /native
parent1404b88ea6ecf5b082d5c33d5f17dc15ce70b310 (diff)
parent54c9815b7b94e1863ebde272c53cc59c7e8be69d (diff)
downloadiced-e187d6ce7bd5e984950fa3e8aa36ccb1337edc9c.tar.gz
iced-e187d6ce7bd5e984950fa3e8aa36ccb1337edc9c.tar.bz2
iced-e187d6ce7bd5e984950fa3e8aa36ccb1337edc9c.zip
Merge pull request #1350 from wyatt-herkamp/paste_event
Added a paste Event to TextInput
Diffstat (limited to '')
-rw-r--r--native/src/widget/text_input.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs
index 98265ef2..fd360cd7 100644
--- a/native/src/widget/text_input.rs
+++ b/native/src/widget/text_input.rs
@@ -66,6 +66,7 @@ where
padding: Padding,
size: Option<u16>,
on_change: Box<dyn Fn(String) -> Message + 'a>,
+ on_paste: Option<Box<dyn Fn(String) -> Message + 'a>>,
on_submit: Option<Message>,
style: <Renderer::Theme as StyleSheet>::Style,
}
@@ -102,6 +103,7 @@ where
padding: Padding::ZERO,
size: None,
on_change: Box::new(on_change),
+ on_paste: None,
on_submit: None,
style: Default::default(),
}
@@ -113,6 +115,16 @@ where
self
}
+ /// Sets the message that should be produced when some text is pasted into
+ /// the [`TextInput`].
+ pub fn on_paste(
+ mut self,
+ on_paste: impl Fn(String) -> Message + 'a,
+ ) -> Self {
+ self.on_paste = Some(Box::new(on_paste));
+ self
+ }
+
/// Sets the [`Font`] of the [`TextInput`].
///
/// [`Font`]: crate::text::Renderer::Font
@@ -225,6 +237,7 @@ pub fn update<'a, Message, Renderer>(
font: &Renderer::Font,
is_secure: bool,
on_change: &dyn Fn(String) -> Message,
+ on_paste: Option<&dyn Fn(String) -> Message>,
on_submit: &Option<Message>,
state: impl FnOnce() -> &'a mut State,
) -> event::Status
@@ -512,7 +525,11 @@ where
editor.paste(content.clone());
- let message = (on_change)(editor.contents());
+ let message = if let Some(paste) = &on_paste {
+ (paste)(editor.contents())
+ } else {
+ (on_change)(editor.contents())
+ };
shell.publish(message);
state.is_pasting = Some(content);
@@ -804,6 +821,7 @@ where
&self.font,
self.is_secure,
self.on_change.as_ref(),
+ self.on_paste.as_deref(),
&self.on_submit,
|| &mut self.state,
)