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

Add copy/paste text handling for MacOS #1015

Open
eruvanos opened this issue Dec 12, 2023 · 10 comments
Open

Add copy/paste text handling for MacOS #1015

eruvanos opened this issue Dec 12, 2023 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@eruvanos
Copy link
Contributor

Is your feature request related to a problem? Please describe.
User would like to copy or paste text from an incremental text layout.

Describe the solution you'd like
Pyglet handles copy/paste like it is doing it for windows or linux.

Additional context
This issue is the result of an investigation why, copy/paste does not work for arcades InputBox, which uses a IncrementalTextLayout.

@eruvanos eruvanos added the enhancement New feature or request label Dec 12, 2023
@eruvanos
Copy link
Contributor Author

Is it possible to add it or is there some major issue with MacOS?

@caffeinepills
Copy link
Collaborator

Clipboard support exists for all OS, however it's not currently exposed in the docs due some issues with Wayland and some Distros. You are free to use it, but just be aware it is finicky with some linux distros.

@eruvanos
Copy link
Contributor Author

eruvanos commented Dec 12, 2023

At this point in time I can only argue, that it is not working. I tried to copy paste from the inputs of: https://github.com/pyglet/pyglet/blob/master/examples/text/text_input.py

M1 Mac

@caffeinepills
Copy link
Collaborator

These are not implemented in the layouts at this time.

They are functions used as part of the Window:
https://github.com/pyglet/pyglet/blob/master/pyglet/window/__init__.py#L801

https://github.com/pyglet/pyglet/blob/master/pyglet/window/__init__.py#L809

@eruvanos
Copy link
Contributor Author

eruvanos commented Dec 12, 2023

A I see, you mean access to the clipboard. But what I understood from the docs, that the text handling supports Deleting, copying, and pasting text.

Also, when I try to add it myself, I do not get key events for [CMD]+X/V/C

@eruvanos
Copy link
Contributor Author

The code for windows and linux, also show some code to support this:
windows

@caffeinepills
Copy link
Collaborator

Unfortunately those are not implemented in layouts or carets. I'm not sure who it was that added those motion events, but they don't work and never have. They must have been under the assumption that those would be system events like other motion events, but they aren't. They don't come as special events from the system, you have to explicitly request to get and write to the clipboard from your application.

Looking at the PR (#508) it probably shouldn't have been approved. Sorry for the confusion.

This could probably be added as a hack to hijack the key combination and dispatch it as a separate event, but I am not sure that's the right answer. However, I'll leave it up to Benjamin on what he wants to do as these are not 'ready' yet.

@benmoran56
Copy link
Member

Just so we're on the same page here, the motion events from #508 are just to dispatch the constants (and they do work as expected on Linux and Windows).
These are just the text motion events, so they don't actually call anything. As pointed out, the Caret doesn't handle those particular motion events.

If the request is just to add the similar motion events for OSX, I think that's fine.

@caffeinepills
Copy link
Collaborator

caffeinepills commented Dec 13, 2023

The problem is, from what it looks like, Windows/Linux is just emulating the events of the NSTextView from MacOS by intercepting key events, and turning them into motion events. By adding custom motion events (copy/paste) we are flipping that, which would require us, to instead, hack a Windows/Linux motion event on MacOS. At that point, doesn't the NSTextView module lose it's purpose? Why have it if we are going to be intercepting key events before it gets to the view? At that point, it should be changed to behave like Windows and Linux. Seems like a lot of work for a motion event that doesn't actually exist? Maybe there is a way to do this with the NSTextView, but I haven't found something that seems like it would fit.

Here are the motion events on Mac: https://developer.apple.com/documentation/appkit/nsstandardkeybindingresponding?language=objc

@eruvanos
Copy link
Contributor Author

eruvanos commented Dec 14, 2023

Mh, to take a step back.
"I would like to be able to implement copy/paste for an IncrementalTextLayout."

  • I am not sure, if those events would be required -> they also would not cover CMD+X
  • Currently I can not detect CMD+X/C/V, but it would be enough to get them.
  • A general implementation within the Caret would be nice, but not necessary.

I found some example about copy/paste for MacOS, but it all looks strange 😅
https://blog.kulman.sk/making-copy-paste-work-with-nstextfield/

From my understanding, currently, the NSTextView handles the copy/paste/cut itself, without effects for pyglet.
which means, that if not self.performKeyEquivalent_(nsevent) (pyglet/window/cocoa/pyglet_textview.py:38) catches the CMD+* combinations and they can not be handled myself.

https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/HandlingKeyEvents/HandlingKeyEvents.html#//apple_ref/doc/uid/10000060i-CH7-SW11

Suggestion:

Within keyDown_ we detect

  • cut
  • past
  • copy
  • all
  • undo
  • redo

and let them pass skipping the performKeyEquivalent_.
(Or create own motion events from them, like it is done for windows and linux. That would allow a general implementation within the Caret)

@caffeinepills caffeinepills self-assigned this Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants