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

egui-winit: Don't consume clipboard shortcuts #3812

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
emilk marked this conversation as resolved.
Show resolved Hide resolved
let consumed = self.egui_ctx.wants_keyboard_input()
|| event.logical_key
== winit::keyboard::Key::Named(winit::keyboard::NamedKey::Tab);
EventResponse {
Expand Down Expand Up @@ -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.
//
Expand Down Expand Up @@ -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;
}
}

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

false
}

/// Call with the output given by `egui`.
Expand Down
Loading