Skip to content

Commit

Permalink
egui-winit: Don't consume clipboard shortcuts (#3812)
Browse files Browse the repository at this point in the history
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to add commits to your PR.
* Remember to run `cargo fmt` and `cargo cranky`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

This breaking change seems to have snuck in during #3649. Previously it
would never consume these, today it consumes them unconditionally, and
with this change it'll ~~only consume them if egui wants text input~~
never consume them.

This is a blocker for updating our application, sadly :(
Dinnerbone authored Jan 17, 2024
1 parent 42013cd commit 221a77d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -341,9 +341,10 @@ impl State {
}
}
WindowEvent::KeyboardInput { event, .. } => {
self.on_keyboard_input(event);

// When pressing the Tab key, egui focuses the first focusable element, hence Tab always consumes.
let consumed = self.on_keyboard_input(event)
|| self.egui_ctx.wants_keyboard_input()
let consumed = self.egui_ctx.wants_keyboard_input()
|| event.logical_key
== winit::keyboard::Key::Named(winit::keyboard::NamedKey::Tab);
EventResponse {
@@ -653,7 +654,7 @@ impl State {
}
}

fn on_keyboard_input(&mut self, event: &winit::event::KeyEvent) -> bool {
fn on_keyboard_input(&mut self, event: &winit::event::KeyEvent) {
let winit::event::KeyEvent {
// Represents the position of a key independent of the currently active layout.
//
@@ -702,18 +703,18 @@ impl State {
if pressed {
if is_cut_command(self.egui_input.modifiers, logical_key) {
self.egui_input.events.push(egui::Event::Cut);
return true;
return;
} else if is_copy_command(self.egui_input.modifiers, logical_key) {
self.egui_input.events.push(egui::Event::Copy);
return true;
return;
} else if is_paste_command(self.egui_input.modifiers, logical_key) {
if let Some(contents) = self.clipboard.get() {
let contents = contents.replace("\r\n", "\n");
if !contents.is_empty() {
self.egui_input.events.push(egui::Event::Paste(contents));
}
}
return true;
return;
}
}

@@ -744,8 +745,6 @@ impl State {
}
}
}

false
}

/// Call with the output given by `egui`.

0 comments on commit 221a77d

Please sign in to comment.