Skip to content

Rename should_propagate_event & add should_prevent_default#5779

Merged
emilk merged 2 commits intoemilk:masterfrom
zystem-io:propagate-events
Mar 30, 2025
Merged

Rename should_propagate_event & add should_prevent_default#5779
emilk merged 2 commits intoemilk:masterfrom
zystem-io:propagate-events

Conversation

@th0rex
Copy link
Contributor

@th0rex th0rex commented Mar 11, 2025

  • I have followed the instructions in the PR template

What

  • Rename WebOptions::should_propagate_event to should_stop_propagation
  • Add WebOptions:: should_prevent_default

Details

Currently eframe calls prevent_default() for all copy / paste events on the document, making embedding an egui application in a page (e.g. an react application) hard (as all copy & paste functionality for other elements on the page is broken by this).

I'm not sure what the motivation for this is, if any.

This commit / PR adds a callback (should_prevent_default), similar to should_propgate_event, that an egui application can use to overwrite this behavior. It defaults to returning true for all events, to keep the existing behavior.

I call should_prevent_default in every place that should_propagate_event is called (which is not all places that prevent_default is called!). I'm not sure for the motivation of not calling should_propagate_event everywhere that stop_propagation is called, but I kept that behavior for the should_prevent_default callback too.

Please let me know if I'm missing some existing functionality that would allow me to do this, or if there's a reason that we don't want applications to be able to customize this (i.e. if there's a reason to always prevent_default for all copy / paste events on the whole document)

@lucasmerlin lucasmerlin added web Related to running Egui on the web eframe Relates to epi and eframe feature New feature or request labels Mar 13, 2025
@github-actions
Copy link

Preview available at https://egui-pr-preview.github.io/pr/5779-propagate-events
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

For consistency with the newly introduced `should_prevent_default`.
Copy link
Collaborator

@lucasmerlin lucasmerlin left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

@emilk emilk changed the title eframe/web: allow customization of prevent_default behavior Rename should_propagate_event & add should_prevent_default Mar 30, 2025
@emilk emilk merged commit ab0f0b7 into emilk:master Mar 30, 2025
25 checks passed
darkwater pushed a commit to darkwater/egui that referenced this pull request Aug 24, 2025
…#5779)

* [x] I have followed the instructions in the PR template

Currently eframe [calls
`prevent_default()`](https://github.com/emilk/egui/blob/962c7c75166dff3369d20675bcfd527d3287149f/crates/eframe/src/web/events.rs#L307-L369)
for all copy / paste events on the
[*document*](https://github.com/emilk/egui/blob/962c7c75166dff3369d20675bcfd527d3287149f/crates/eframe/src/web/events.rs#L88),
making embedding an egui application in a page (e.g. an react
application) hard (as all copy & paste functionality for other elements
on the page is broken by this).

I'm not sure what the motivation for this is, if any.

This commit / PR adds a callback (`should_prevent_default`), similar to
`should_propgate_event`, that an egui application can use to overwrite
this behavior. It defaults to returning `true` for all events, to keep
the existing behavior.

I call `should_prevent_default` in every place that
`should_propagate_event` is called (which is not all places that
`prevent_default` is called!). I'm not sure for the motivation of not
calling `should_propagate_event` everywhere that `stop_propagation` is
called, but I kept that behavior for the `should_prevent_default`
callback too.

Please let me know if I'm missing some existing functionality that would
allow me to do this, or if there's a reason that we don't want
applications to be able to customize this (i.e. if there's a reason to
always `prevent_default` for all copy / paste events on the whole
document)
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 feature New feature or request web Related to running Egui on the web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants