Skip to content

Commit

Permalink
Don't consume clipboard shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinnerbone committed Jan 12, 2024
1 parent 301c72b commit bdecb2c
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
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()
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

0 comments on commit bdecb2c

Please sign in to comment.