Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix copy and cut on Safari #3513

Merged
merged 1 commit into from
Nov 21, 2023
Merged

Fix copy and cut on Safari #3513

merged 1 commit into from
Nov 21, 2023

Conversation

lunixbochs
Copy link
Contributor

@lunixbochs lunixbochs commented Oct 30, 2023

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.

@lunixbochs
Copy link
Contributor Author

I also noticed middle clicking a "source code" URL in egui.rs triggers Safari's popup blocker. This is likely the same issue - eframe should run logic headlessly from inside the click handler so it inherits the "user interaction" permissions when processing the click.

Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thank you!

"cut",
|event: web_sys::ClipboardEvent, runner| {
runner.input.raw.events.push(egui::Event::Cut);
runner.logic();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
runner.logic();
// In Safari we are only allowed to write to the clipboard during the
// event callback, which is why we run the app logic here and now.
runner.logic();

&document,
"copy",
|event: web_sys::ClipboardEvent, runner| {
runner.input.raw.events.push(egui::Event::Copy);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
runner.input.raw.events.push(egui::Event::Copy);
runner.input.raw.events.push(egui::Event::Copy);
// In Safari we are only allowed to write to the clipboard during the
// event callback, which is why we run the app logic here and now.

@emilk emilk added web Related to running Egui on the web eframe Relates to epi and eframe labels Nov 10, 2023
@emilk emilk changed the title fix #3480 - copy doesn't work on Safari Fix copy and cut on Safari Nov 10, 2023
@emilk emilk added this to the 0.24.0 milestone Nov 21, 2023
@emilk emilk merged commit a6da343 into emilk:master Nov 21, 2023
8 of 21 checks passed
emilk added a commit that referenced this pull request Nov 24, 2023
* Closes lampsitter/egui_commonmark#21

Follow-up to #3513

Safari only allows access to the clipboard as response to user action,
so we need to take an extra logic step right in the event handler.
emilk added a commit that referenced this pull request Nov 24, 2023
* Follow-up to #3621 and
#3513

To work around a Safari limitation, we run the app logic in the event
handler of copy, cut, and mouse up and down.

Previously the output of that frame was discarded, but in this PR it is
now saved to be used in the next requestAnimationFrame.

The result is noticeable more distinct clicks on buttons (one more frame
of highlight)

Bonus: also fix auto-save of a sleeping web app
emilk pushed a commit to rerun-io/rerun that referenced this pull request Dec 1, 2023
…d guides (#4300)

### What

egui 0.24 will fix the bug where coping from Safari was impossible:
- emilk/egui#3513

This PR removes the related warnings in the in-app Getting Started
guides.

- May be blocked by
lampsitter/egui_commonmark#21??
- Blocked by #4111
- Fixes #4292

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/4300) (if
applicable)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG

- [PR Build Summary](https://build.rerun.io/pr/4300)
- [Docs
preview](https://rerun.io/preview/0a0e58f6c169798c01d1932ecec3fb51cfe6360e/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/0a0e58f6c169798c01d1932ecec3fb51cfe6360e/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eframe Relates to epi and eframe web Related to running Egui on the web
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Copy doesn't work on Safari
2 participants