Skip to content

Commit 4f670bd

Browse files
committed
eframe web: forward cmd-S/O to egui app (stop default browser action)
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.
1 parent 8eda32e commit 4f670bd

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

crates/eframe/src/web/events.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,16 @@ fn should_prevent_default_for_key(
219219
// * cmd-shift-C (debug tools)
220220
// * cmd/ctrl-c/v/x (lest we prevent copy/paste/cut events)
221221

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

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

0 commit comments

Comments
 (0)