eframe/web: allow customization of prevent_default
behavior
#5779
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 toshould_propgate_event
, that an egui application can use to overwrite this behavior. It defaults to returningtrue
for all events, to keep the existing behavior.I call
should_prevent_default
in every place thatshould_propagate_event
is called (which is not all places thatprevent_default
is called!). I'm not sure for the motivation of not callingshould_propagate_event
everywhere thatstop_propagation
is called, but I kept that behavior for theshould_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)