-
Notifications
You must be signed in to change notification settings - Fork 568
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
Copying and pasting in textbox does not work (at least on windows) #1030
Comments
I think this boils down to flaws in key handling at lower levels, which is on our radar. Thanks for the report, we'll keep it open. |
I had to add and Edit menu in order to get copy/paste/cut to work on Windows. Haven't gone too deep on other platforms. |
If I'm experiencing issues with the crochet |
Yes, that's druid; the textbox is finicky and doesn't play super well with crochet. :( |
@konkers can you explain what workaround did you do ? Any docs? |
I had to add a menu to the window with the text box with actions for cut, copy, and paste along with their shortcuts. No docs really, just got the menu setup. |
@konkers hmm is there any snippets of code that do this. |
Here's how I did it. It's old-ish code, so it may not work with current versions of Druid: |
Can confirm the bug on Linux. The @konkers's solution works. But I don't need a menu to be shown. Is there a way to hide it? |
There's a slightly annoying way: You can manually add a controller in front of your textbox that handles the shortcuts you want, and then dispatches the same commands that are dispatched by the menus; see here: https://github.com/linebender/druid/blob/master/druid/src/menu.rs#L464. |
I hope I'm not adding noise as I'm very new to the code base, but there is an https://github.com/linebender/druid/blob/master/druid/src/text/text_input.rs It feels to me like that file is missing a shortcut for it? Something like:
I'm testing this now, looks like accessing the clipboard in that file is difficult, maybe it should be: |
Yea paste is sort of a funny case. The original rationale was that paste works a lot like things like drag and drop, and we wanted to support those too. In any case, how it works: the user (normally a menu) sends the |
Thank you for reply. Only today I've got a notification on my email :) use druid::{
commands, widget::Controller, Data, Env, Event, EventCtx, HotKey, SysMods, Target, Widget,
};
pub struct CopyCutPasteController;
impl<T: Data, W: Widget<T>> Controller<T, W> for CopyCutPasteController {
fn event(&mut self, child: &mut W, ctx: &mut EventCtx, event: &Event, data: &mut T, env: &Env) {
match event {
Event::KeyDown(key_event) => match key_event {
k_e if (HotKey::new(SysMods::Cmd, "c")).matches(k_e) => {
ctx.submit_command(commands::COPY.to(Target::Auto));
ctx.set_handled();
}
k_e if (HotKey::new(SysMods::Cmd, "x")).matches(k_e) => {
ctx.submit_command(commands::CUT.to(Target::Auto));
ctx.set_handled();
}
k_e if (HotKey::new(SysMods::Cmd, "v")).matches(k_e) => {
ctx.submit_command(commands::PASTE.to(Target::Auto));
ctx.set_handled();
}
_ => (),
},
_ => (),
}
child.event(ctx, event, data, env);
}
} |
That works in Windows 10, I think it should be added automatically somehow if the user doesn't have menus. Many applications in Windows don't have menus. The examples right now feel a bit broken for a newbie when the copy & paste doesn't work out of box, which I think is not ideal for first impression of this great library. |
My priority with the textbox right now is to rewrite it on top of the patch adding IME support; that's going to change how a lot of these interactions are wired, and then we can revisit this. IME tracking: #1308 this was intended to be my main goal for this week, but I've ended up being waylayed a few times already... 😒 |
The textbox will now receive copy/cut/paste/undo/redo/select-all without a menu being present. Several of these (select-all, undo/redo) do not currently have implementations, but we will at least get the commands. - progress on linebender#1652 - closes linebender#1030
When pressing "ctrl+v" on windows inside the textbox, the text "\u{16}" is inserted. I am not sure where this exactly comes from but the event "Event::Paste" is never raised and therefore clipboard code never ran. Instead the code execution goes into BasicTextInput's handle_event() and the is_printable() if-check.
Pressing "ctrl+c" and "ctrl+x" both deletes the text inside the textbox when only "ctrl+x" should delete it. The text is never copied to the clipboard in both cases.
The text was updated successfully, but these errors were encountered: