Parcourir la source

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
Fabio Alessandrelli il y a 6 ans
Parent
commit
2b436dd50e
1 fichiers modifiés avec 10 ajouts et 0 suppressions
  1. 10 0
      platform/javascript/os_javascript.cpp

+ 10 - 0
platform/javascript/os_javascript.cpp

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