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

Copy Paste (Clipboard) Keyboard Shortcut Issue #1055

Closed
matthewmullin01 opened this issue Oct 17, 2020 · 14 comments
Closed

Copy Paste (Clipboard) Keyboard Shortcut Issue #1055

matthewmullin01 opened this issue Oct 17, 2020 · 14 comments

Comments

@matthewmullin01
Copy link

matthewmullin01 commented Oct 17, 2020

I have noticed that using the keyboard shortcuts (cmd/ctrl-c and cmd/ctrl-v) to copy or paste text from a input field does not work.

I have however seen that using the right click context menu works as expected.

Note I am on MacOS 11.

To Reproduce

  1. Download and Install official Tauri example app from https://tauri.studio/en/docs/get-started/setup-macos
  2. Run App
  3. Go to Communication tab
  4. Enter text in the text box
  5. Notice that you cannot select all copy or paste using keyboard shortcuts.

Screenshots
image

Platform and Versions (please complete the following information):

OS: Mac OS 11
Node: v12.18.3
NPM: 6.14.6
Yarn: 0.1.0
Rustc: 1.46.0 (04488afe3 2020-08-24)

@matthewmullin01 matthewmullin01 changed the title Copy Paste (Clipboard) Shortcut Issue Copy Paste (Clipboard) Keyboard Shortcut Issue Oct 17, 2020
@lucasfernog
Copy link
Member

Hmm I thought webview/webview#405 would fix this. @abemedia do you know something about this?

@virtualgraham
Copy link

I have the same issue, also ctrl z does not undo text input like it does in the browser.

@abemedia
Copy link

@lucasfernog that PR only allows clipboard access from JS. You still need to write the JS event to capture it.

@matthewmullin01
Copy link
Author

matthewmullin01 commented Oct 18, 2020

Thanks for the leads. Don't know how I didn't find anything related to this when searching.

For those wondering the solution is to listen for a copy or paste event and simply call document.execCommand('copy'); or document.execCommand('paste');

Rudimentary vue example below.

<template>
  <Editor @keydown.meta.86="pasteEvent()" @keydown.meta.67="copyEvent()"  ... />
</template>

<script>
// ...
  copyEvent() {
    document.execCommand('copy');
  }

  pasteEvent() {
    document.execCommand('paste');
  }
// ...
</script>

@virtualgraham
Copy link

virtualgraham commented Oct 18, 2020

@matthewmullin01 The cmd-c copy event works fine. The cmd-v paste event causes a content menu to appear with a paste option that you still have to click on to actually paste. Also there is a system beep that needs to be prevented by calling event.preventDefault(). This is on Mac.

@nklayman
Copy link
Member

Just for reference, everything works as intended on Linux.

@nklayman
Copy link
Member

This has been fixed in the dev branch of Tauri and will be available in the next release.

@lukeed
Copy link

lukeed commented May 21, 2021

I'm still seeing the contextmenu show up on paste while using macOS and tauri@1.0.0-beta.1

Not sure if this version was the "next release"

@AlexHayton
Copy link

AlexHayton commented Jul 5, 2021

I'm also seeing the same behaviour... :(
This is on 1.0.0-beta.2

@serkandemirel0420
Copy link

serkandemirel0420 commented Dec 11, 2021

I have still the problem and also beeps. yes, it beeps. Even in textbox, cmd+a not possible.

@gdotdesign
Copy link

I'm running into the same issue.

@FabianLars
Copy link
Member

For shurtcuts like this to work on macos you need to add a window menu. See #2397 for more or this template for inspiration.

The beeping sound is also known, see #2626. Unfortunetly we haven't found a solution so far.

@gdotdesign
Copy link

@FabianLars thank you!

@gdotdesign
Copy link

Managed to make it work with the A menu as you suggested but with some differences because the template used not sable API.

let about_menu = Submenu::new("App", Menu::new()
  .add_native_item(MenuItem::Hide)
  .add_native_item(MenuItem::HideOthers)
  .add_native_item(MenuItem::ShowAll)
  .add_native_item(MenuItem::Separator)
  .add_native_item(MenuItem::Quit));

let edit_menu = Submenu::new("Edit", Menu::new()
  .add_native_item(MenuItem::Undo)
  .add_native_item(MenuItem::Redo)
  .add_native_item(MenuItem::Separator)
  .add_native_item(MenuItem::Cut)
  .add_native_item(MenuItem::Copy)
  .add_native_item(MenuItem::Paste)
  .add_native_item(MenuItem::SelectAll));

let view_menu = Submenu::new("View", Menu::new()
  .add_native_item(MenuItem::EnterFullScreen));

let window_menu = Submenu::new("Window", Menu::new()
  .add_native_item(MenuItem::Minimize)
  .add_native_item(MenuItem::Zoom));

let help_menu = Submenu::new("Help", Menu::new()
  .add_item(CustomMenuItem::new("Learn More", "Learn More")));

let menu = Menu::new()
  .add_submenu(about_menu)
  .add_submenu(edit_menu)
  .add_submenu(view_menu)
  .add_submenu(window_menu)
  .add_submenu(help_menu);

app
.menu(menu)
.on_menu_event(|event| {
  let event_name = event.menu_item_id();
  match event_name {
    "Learn More" => {
      shell::open(
        "https://www.my-app.com".to_string(),
        None,
      )
      .unwrap();
    }
    _ => {}
  }
})

Let it be known that there are some not specified menu items show up (probably the OS adds them???). Also, this should be added to the official documentation at some point :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants