Skip to content

Commit

Permalink
Fix copy and cut on Safari (#3513)
Browse files Browse the repository at this point in the history
* Closes <#3480>

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.
  • Loading branch information
lunixbochs authored Nov 21, 2023
1 parent 6adc486 commit a6da343
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions crates/eframe/src/web/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down

0 comments on commit a6da343

Please sign in to comment.