Skip to content

Commit

Permalink
eframe web: forward cmd-S/O to egui app (stop default browser action)
Browse files Browse the repository at this point in the history
This allow eframe apps to capture cmd-S and cmd-O to trigger their
own save and open actions, instead of having the browser do something
annoying.
  • Loading branch information
emilk committed Jan 30, 2025
1 parent 8eda32e commit 4f670bd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions crates/eframe/src/web/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,16 @@ fn should_prevent_default_for_key(
// * cmd-shift-C (debug tools)
// * cmd/ctrl-c/v/x (lest we prevent copy/paste/cut events)

// Prevent ctrl-P from opening the print dialog. Users may want to use it for a command palette.
if egui_key == egui::Key::P && (modifiers.ctrl || modifiers.command || modifiers.mac_cmd) {
return true;
// Prevent cmd/ctrl plus these keys from triggering the default browser action:
let keys = [
egui::Key::O, // open
egui::Key::P, // print (cmd-P is common for command palette)
egui::Key::S, // save
];
for key in keys {
if egui_key == key && (modifiers.ctrl || modifiers.command || modifiers.mac_cmd) {
return true;
}
}

if egui_key == egui::Key::Space && !runner.text_agent.has_focus() {
Expand Down

0 comments on commit 4f670bd

Please sign in to comment.