JPro-one / JPro-Tickets

The right place to report about bugs or suggest improvements for JPro.
https://www.jpro.one
9 stars 4 forks source link

Clipboard features with JPro #149

Open guirak opened 1 year ago

guirak commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Ok, good. Thank you.

grubbcc commented 4 months ago

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 commented 4 months ago

@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.