This repository was archived by the owner on Dec 12, 2023. It is now read-only.
Open
Conversation
…sed to the JavaScript event handlers.
…LCopyAndPasteAPI.cs" before the "using" directives, so it can be uncommented without errors or having to move it manually.
…rol" and "command" properties set as true, which works on both mac and Windows with only one "ProcessEvent" call. Moved the event creation to a separate method.
…ld, instead of first checking for a legacy input field, to save a check in most situations.
…isually updated in some situations.
Owner
|
Thanks for the PR ❤️ What do you think about you becoming the main repo for this? I'm not actually a Unity developer. I wrote this a just kind of a 1 day hobby thing. I'm not sure I've used Unity in over a year, maybe 2yrs |
Author
|
That would be OK. I've never done a repo transfer or similar, how do you want to do it? |
Owner
|
I think I can just mark this repo as archived after I've changed the README to point to https://github.com/Trisibo/unity-webgl-copy-and-paste/ |
…ysLinkAssembly" to the assembly.
…teAPI" class to the "WebGLCopyAndPaste" namespace.
…e, and added TextMesh Pro fields.
…ow should work in more circumstances, previously it didn't work in non-secure pages, or iframes without clipboard permissions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I made several fixes and improvements, I'm opening a single pull request with all of them, sorry if you preferred one pull request per change. These are the changes:
When I tested on Firefox on Windows, pasting didn't work at all. Apparently, setting
GUIUtility.systemCopyBufferto paste doesn't work there (not sure about other browsers, I don't even know why it works on some, seems a weird behaviour to me), so I added aSendKey("v")call, but then in some browsers it would paste the text twice. What seems to work on all browsers is to setGUIUtility.systemCopyBuffer, then callSendKey("v"), and then setGUIUtility.systemCopyBuffertonull, which prevents the second paste (it occurs on the next frame, so at that point it has no text). The only issue would be that other code cannot useGUIUtility.systemCopyBufferat that point to know what was pasted, but I consider it a very minor issue compared to pasting not working at all in some browsers.Added the
forceLabelUpdateparameter toSendKey, used when pasting, since in some browsers the text was pasted but the label wasn't updated visually until another key was pressed. I usedForceLabelUpdateto do the update.When creating a keyboard event for processing, instead of using the base key with added "%" and "^" texts and calling
ProcessEventtwice, now the code creates an event with the key unchanged and thecontrolandcommandproperties set to true, which works fine on both Windows and Mac with just one call toProcessEvent.Substituted the deprecated
Window.eventproperty with the event passed to the JavaScript event handlers: https://developer.mozilla.org/en-US/docs/Web/API/Window/eventMoved the
#define WEBGL_COPY_AND_PASTE_SUPPORT_TEXTMESH_PROline before the usings, just for convenience so it can be uncommented right away without having to move it due to defines being invalid elsewhere in code.When TextMesh Pro support is enabled, the code will check if the object has a TextMesh Pro field first, instead of first checking for a legacy field; most of the time, when TMP support is added it would be expected that objects use a TMP field, so checking that first would avoid the check for the legacy one in most cases.
Added a check to ensure
EventSystem.currentis not null before using it.I have confirmed that it works on: