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

Copying and pasting in textbox does not work (at least on windows) #1030

Closed
rhzk opened this issue Jun 13, 2020 · 15 comments · Fixed by #1660
Closed

Copying and pasting in textbox does not work (at least on windows) #1030

rhzk opened this issue Jun 13, 2020 · 15 comments · Fixed by #1660
Labels
bug does not behave the way it is supposed to shell concerns the shell abstraction text

Comments

@rhzk
Copy link
Collaborator

rhzk commented Jun 13, 2020

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.

@raphlinus
Copy link
Contributor

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.

@luleyleo luleyleo added bug does not behave the way it is supposed to shell concerns the shell abstraction labels Jun 13, 2020
@konkers
Copy link
Contributor

konkers commented Jun 15, 2020

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.

@jplatte
Copy link
Member

jplatte commented Jan 8, 2021

If I'm experiencing issues with the crochet TextBox, that's probably because of druid, right? I think I'm experiencing a similar / related issue on Linux (none of the usual keyboard shortcuts do anything except reset the cursor blink cycle).

@cmyr
Copy link
Member

cmyr commented Jan 13, 2021

Yes, that's druid; the textbox is finicky and doesn't play super well with crochet. :(

@shirshak55
Copy link

@konkers can you explain what workaround did you do ? Any docs?

@konkers
Copy link
Contributor

konkers commented Jan 17, 2021

@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.

@shirshak55
Copy link

@konkers hmm is there any snippets of code that do this.

@konkers
Copy link
Contributor

konkers commented Jan 17, 2021

Here's how I did it. It's old-ish code, so it may not work with current versions of Druid:
https://github.com/konkers/pollendina/blob/9841cdd2a485207ab24bf3ca0b806d1a7d93164b/src/main.rs#L114
https://github.com/konkers/pollendina/blob/9841cdd2a485207ab24bf3ca0b806d1a7d93164b/src/main.rs#L415

@asusha94
Copy link

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?

@cmyr
Copy link
Member

cmyr commented Jan 25, 2021

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.

@Ciantic
Copy link
Collaborator

Ciantic commented Feb 9, 2021

I hope I'm not adding noise as I'm very new to the code base, but there is an EditAction called Paste(String) but it doesn't have keyboard shortcut defined like the others in the following file:

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:

            k_e if (HotKey::new(SysMods::Cmd, "v")).matches(k_e) => {
                EditAction::Paste(SomeHowGetItFromClipboard())
            }

I'm testing this now, looks like accessing the clipboard in that file is difficult, maybe it should be: EditAction::Paste and not EditAction::Paste(String) this way the receiver can introspect the clipboard and determine can it read it.

@cmyr
Copy link
Member

cmyr commented Feb 9, 2021

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 PASTE command to the root, and then druid handles this. and sends Event::Paste. This event sends a handle to a clipboard object that can be used to retrieve the contents of the system clipboard, but there's no real reason we couldn't make this available in other ways.

@asusha94
Copy link

asusha94 commented Feb 9, 2021

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.

Thank you for reply. Only today I've got a notification on my email :)
The approach works, even if the controller is placed in a root widget of a window:

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);
    }
}

@Ciantic
Copy link
Collaborator

Ciantic commented Feb 9, 2021

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.

@cmyr
Copy link
Member

cmyr commented Feb 17, 2021

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
initial impl: #1378

this was intended to be my main goal for this week, but I've ended up being waylayed a few times already... 😒

@cmyr cmyr added the text label Mar 11, 2021
@cmyr cmyr added this to the textbox-polish milestone Mar 11, 2021
cmyr added a commit that referenced this issue Mar 17, 2021
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 #1652
- closes #1030
cmyr added a commit that referenced this issue Mar 17, 2021
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 #1652
- closes #1030
cmyr added a commit that referenced this issue Mar 17, 2021
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 #1652
- closes #1030
cmyr added a commit that referenced this issue Mar 30, 2021
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 #1652
- closes #1030
cmyr added a commit that referenced this issue Mar 30, 2021
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 #1652
- closes #1030
richard-uk1 pushed a commit to richard-uk1/druid that referenced this issue Apr 6, 2021
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug does not behave the way it is supposed to shell concerns the shell abstraction text
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants