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

Clipboard features with JPro #149

Open
guirak opened this issue Apr 13, 2023 · 4 comments
Open

Clipboard features with JPro #149

guirak opened this issue Apr 13, 2023 · 4 comments

Comments

@guirak
Copy link

guirak commented Apr 13, 2023

Hi Florian,

Is there a way to use something similar than the native Clipboard with JPRO ?

final Clipboard clipboard = Clipboard.getSystemClipboard();
final ClipboardContent content = new ClipboardContent();
content.putString(tokenProperty.get());
clipboard.setContent(content);

Thank you

@FlorianKirmaier
Copy link
Contributor

That's very tricky at the moment.
The Browser APIs to access the clipboard is still experimental (and only work after explicit approval by the user)
But it should be implementable now.
So it's something we should do when we have some time left.

@guirak
Copy link
Author

guirak commented Apr 20, 2023

Ok, good. Thank you.

@grubbcc
Copy link

grubbcc commented Mar 3, 2024

I had trouble with copy-paste until I tried this:

KeyCombination copyKey = new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_DOWN);
chatBox.addEventHandler(KeyEvent.KEY_PRESSED, keyEvent -> {
	if(copyKey.match(keyEvent)) {
		getWebAPI().executeScript("""
                        navigator.clipboard.writeText("%s");
			""".formatted(chatBox.getSelectedText()));
	}
});

@FlorianKirmaier
Copy link
Contributor

@grubbcc
If I remember correctly, this doesn't work on Safari.
Generally, accessing the Clipboard is usually only limited possible.
We have a utility class: https://github.com/JPro-one/JPro-Platform/blob/b0b83777b7de64af341933e62feddcfe1d269a75/jpro-routing/core/src/main/scala/one/jpro/platform/routing/CopyUtil.scala#L14
This class allows to setup "Copy on Click"
You have to live with the restriction that the text to copy has to be known before the click.

It's also possible to access the Clipboard API: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API
But this requires approval by the user.

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

No branches or pull requests

3 participants