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 (Cmd+C) and Paste (Cmd+V) do not work in text controls on Mac. Bug: paste is executed twice. #161

Closed
GoogleCodeExporter opened this issue Aug 28, 2015 · 7 comments

Comments

@GoogleCodeExporter
Copy link

GoogleCodeExporter commented Aug 28, 2015

Copy (Cmd+C) and Paste (Cmd+V) do not work in text controls on Mac. Created topic on the CEF Forum: http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=12561

Original issue reported on code.google.com by czarek.t...@gmail.com on 11 Jan 2015 at 6:46

@GoogleCodeExporter
Copy link
Author

GoogleCodeExporter commented Aug 28, 2015

Marshall responed on the CEF Forum:

Shortcuts are handled via the application top menu on Mac where methods called by key 
bindings are defined in the XIB file (for example cefclient/mac/English.lproj/MainMenu.xib).
If that doesn't exist you probably need to implement performKeyEquivalent.

Original comment by czarek.t...@gmail.com on 12 Jan 2015 at 5:08

@kocrotus
Copy link

The copy and paste can be done by adding script to the cefpython client handler

The client handler is in : OnKeyEvent handler. The windows and linux somehow able to use Ctrl-C and Ctrl-v, but the Mac dev need to add some code like this

def OnKeyEvent(self, browser, event, eventHandle):
     if get_platform()==PLATFORM_MAC:
            if event["modifiers"]==128:
                if event["native_key_code"]==8:
                    mainBrowser.GetFocusedFrame().copy()
                elif event["native_key_code"]==9:
                    mainBrowser.GetFocusedFrame().paste()

                return False

the get_platform() and PLATFORM_MAC are variable. The mainBrowser is the instance returned by the cefpython.CreateBrowserSync() call.

I don't know if this ability need to be part of the cefpython or must be implemented independently by the developer, but sure is the windows and Linux can do copy-paste without additional coding.

@cztomczak
Copy link
Owner

Fixed in commit c23bc2d. v56 release coming soon. Copy/paste commands are now handled by default. You can still overwrite this behavior by implementing OnKeyEvent and returning True. CEF Python checks for return value and if True it won't handle these commands.

@cztomczak cztomczak added this to the v56 milestone Mar 3, 2017
@cztomczak
Copy link
Owner

There seems a bug was introduced with the default implementation for Copy/Paste. These commands are executed twice in one of user's app. Here is the code:

# Handle paste: command + v
            elif pyEvent["modifiers"] == 128 \
                    and pyEvent["native_key_code"] == 9:
                pyBrowser.GetFocusedFrame().Paste()
                return True

There should be a check: pyEvent["type"] = cef.KEYEVENT_RAWKEYDOWN.

Additionally support for more shortcuts should be added:

  • native_key_code 0 SelectAll()
  • native_key_code 6 Undo()
  • native_key_code 7 Cut()
  • modifiers 130 native_key_code 6 Redo()

@cztomczak cztomczak reopened this Jun 20, 2017
@cztomczak cztomczak changed the title Copy (Cmd+C) and Paste (Cmd+V) do not work in text controls on Mac Copy (Cmd+C) and Paste (Cmd+V) do not work in text controls on Mac. Bug: paste is executed twice. Jun 20, 2017
@jungnoh
Copy link

jungnoh commented May 22, 2018

Is this issue fixed? I'm still having the issue of pasting twice on High Sierra.

@cztomczak
Copy link
Owner

@studiodoth You can fix this in your app by implementing OnKeyEvent and using code from my previous comment.

@cztomczak cztomczak modified the milestones: v56, v66 May 22, 2018
cztomczak added a commit that referenced this issue Aug 16, 2018
Handle: copy, paste, cut, undo, redo, select all.
@cztomczak
Copy link
Owner

Fix double paste and handle more keyboard shortcuts on Mac in rev 8a20fdb.
Handle: copy, paste, cut, undo, redo, select all.

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

4 participants