From a6da34339a254ea6d24e47786fd3cae3d85f17d2 Mon Sep 17 00:00:00 2001 From: Ryan Hileman Date: Tue, 21 Nov 2023 05:54:31 -0800 Subject: [PATCH] Fix copy and cut on Safari (#3513) * Closes I've tested this on Safari and Chrome on macOS Sonoma 14.0. Could be improved to only call `event.preventDefault()` if `runner.logic()` actually performed a copy, but I don't see a way to get that information out with the current API. --- crates/eframe/src/web/events.rs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/crates/eframe/src/web/events.rs b/crates/eframe/src/web/events.rs index 907d7f8e60a..4f648f1fe98 100644 --- a/crates/eframe/src/web/events.rs +++ b/crates/eframe/src/web/events.rs @@ -172,16 +172,30 @@ pub(crate) fn install_document_events(runner_ref: &WebRunner) -> Result<(), JsVa )?; #[cfg(web_sys_unstable_apis)] - runner_ref.add_event_listener(&document, "cut", |_: web_sys::ClipboardEvent, runner| { - runner.input.raw.events.push(egui::Event::Cut); - runner.needs_repaint.repaint_asap(); - })?; + runner_ref.add_event_listener( + &document, + "cut", + |event: web_sys::ClipboardEvent, runner| { + runner.input.raw.events.push(egui::Event::Cut); + runner.logic(); + runner.needs_repaint.repaint_asap(); + event.stop_propagation(); + event.prevent_default(); + }, + )?; #[cfg(web_sys_unstable_apis)] - runner_ref.add_event_listener(&document, "copy", |_: web_sys::ClipboardEvent, runner| { - runner.input.raw.events.push(egui::Event::Copy); - runner.needs_repaint.repaint_asap(); - })?; + runner_ref.add_event_listener( + &document, + "copy", + |event: web_sys::ClipboardEvent, runner| { + runner.input.raw.events.push(egui::Event::Copy); + runner.logic(); + runner.needs_repaint.repaint_asap(); + event.stop_propagation(); + event.prevent_default(); + }, + )?; Ok(()) }