Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextBox can receive EditAction commands #814

Merged
merged 1 commit into from
Apr 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion druid/src/widget/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ pub struct TextBox {
}

impl TextBox {
/// Perform an `EditAction`. The payload *must* be an `EditAction`.
pub const PERFORM_EDIT: Selector = Selector::new("druid-builtin.textbox.perform-edit");

/// Create a new TextBox widget
pub fn new() -> TextBox {
Self {
Expand Down Expand Up @@ -237,7 +240,9 @@ impl Widget<String> for TextBox {

match event {
Event::MouseDown(mouse) => {
ctx.request_focus();
if !ctx.has_focus() {
ctx.request_focus();
}
ctx.set_active(true);

let cursor_offset = self.offset_for_point(mouse.pos, &text_layout);
Expand Down Expand Up @@ -289,6 +294,12 @@ impl Widget<String> for TextBox {
ctx.set_handled();
}
Event::Command(cmd) if cmd.selector == RESET_BLINK => self.reset_cursor_blink(ctx),
Event::Command(cmd) if cmd.selector == TextBox::PERFORM_EDIT => {
let edit = cmd
.get_object::<EditAction>()
.expect("PERFORM_EDIT contained non-edit payload");
self.do_edit_action(edit.to_owned(), data);
}
Event::Paste(ref item) => {
if let Some(string) = item.get_string() {
edit_action = Some(EditAction::Paste(string));
Expand Down