Kinda working HTML5 clipboard paste.

Listen to paste events to update local clipboard.
CTRL+V still not working out of the box.
To do that, We would need to change how we handle keypress, most likely
making it worse and less safe. In the end, I'm not sure we can fix it
properly for now. Maybe in the future, with the Clipboard API, support
of which is still pretty limited on chrome, and only available to
extensions in Firefox.

For now, you can paste via:
- Browser bar -> Edit -> Paste.
- Middle mouse click (Linux only, copies secondary clipboard).

And THEN press CTRL+V
This commit is contained in:
Fabio Alessandrelli 2019-05-28 22:27:03 +02:00
parent 0f76df2397
commit 2b436dd50e

View file

@ -796,6 +796,11 @@ const char *OS_JavaScript::get_audio_driver_name(int p_driver) const {
}
// Clipboard
extern "C" EMSCRIPTEN_KEEPALIVE void update_clipboard(const char *p_text) {
// Only call set_clipboard from OS (sets local clipboard)
OS::get_singleton()->OS::set_clipboard(p_text);
}
void OS_JavaScript::set_clipboard(const String &p_text) {
OS::set_clipboard(p_text);
/* clang-format off */
@ -958,6 +963,11 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
(['mouseover', 'mouseleave', 'focus', 'blur']).forEach(function(event, index) {
Module.canvas.addEventListener(event, send_notification.bind(null, notifications[index]));
});
// Clipboard
const update_clipboard = cwrap('update_clipboard', null, ['string']);
window.addEventListener('paste', function(evt) {
update_clipboard(evt.clipboardData.getData('text'));
}, true);
},
MainLoop::NOTIFICATION_WM_MOUSE_ENTER,
MainLoop::NOTIFICATION_WM_MOUSE_EXIT,