1
- use super :: * ;
2
1
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
3
2
3
+ use egui:: Key ;
4
+
5
+ use super :: * ;
6
+
4
7
struct IsDestroyed ( pub bool ) ;
5
8
6
9
pub fn paint_and_schedule (
@@ -64,8 +67,9 @@ pub fn install_document_events(runner_container: &mut AppRunnerContainer) -> Res
64
67
runner_lock. input . raw . modifiers = modifiers;
65
68
66
69
let key = event. key ( ) ;
70
+ let egui_key = translate_key ( & key) ;
67
71
68
- if let Some ( key) = translate_key ( & key ) {
72
+ if let Some ( key) = egui_key {
69
73
runner_lock. input . raw . events . push ( egui:: Event :: Key {
70
74
key,
71
75
pressed : true ,
@@ -85,10 +89,13 @@ pub fn install_document_events(runner_container: &mut AppRunnerContainer) -> Res
85
89
86
90
let egui_wants_keyboard = runner_lock. egui_ctx ( ) . wants_keyboard_input ( ) ;
87
91
88
- let prevent_default = if matches ! ( event. key( ) . as_str( ) , "Tab" ) {
92
+ #[ allow( clippy:: if_same_then_else) ]
93
+ let prevent_default = if egui_key == Some ( Key :: Tab ) {
89
94
// Always prevent moving cursor to url bar.
90
95
// egui wants to use tab to move to the next text field.
91
96
true
97
+ } else if egui_key == Some ( Key :: P ) {
98
+ true // Prevent ctrl-P opening the print dialog. Users may want to use it for a command palette.
92
99
} else if egui_wants_keyboard {
93
100
matches ! (
94
101
event. key( ) . as_str( ) ,
@@ -112,6 +119,7 @@ pub fn install_document_events(runner_container: &mut AppRunnerContainer) -> Res
112
119
113
120
if prevent_default {
114
121
event. prevent_default ( ) ;
122
+ // event.stop_propagation();
115
123
}
116
124
} ,
117
125
) ?;
@@ -198,15 +206,21 @@ pub fn install_document_events(runner_container: &mut AppRunnerContainer) -> Res
198
206
pub fn install_canvas_events ( runner_container : & mut AppRunnerContainer ) -> Result < ( ) , JsValue > {
199
207
let canvas = canvas_element ( runner_container. runner . lock ( ) . canvas_id ( ) ) . unwrap ( ) ;
200
208
201
- {
209
+ let prevent_default_events = [
202
210
// By default, right-clicks open a context menu.
203
211
// We don't want to do that (right clicks is handled by egui):
204
- let event_name = "contextmenu" ;
212
+ "contextmenu" ,
213
+ // Allow users to use ctrl-p for e.g. a command palette
214
+ "afterprint" ,
215
+ ] ;
205
216
217
+ for event_name in prevent_default_events {
206
218
let closure =
207
219
move |event : web_sys:: MouseEvent ,
208
220
mut _runner_lock : egui:: mutex:: MutexGuard < ' _ , AppRunner > | {
209
221
event. prevent_default ( ) ;
222
+ // event.stop_propagation();
223
+ // tracing::debug!("Preventing event {:?}", event_name);
210
224
} ;
211
225
212
226
runner_container. add_event_listener ( & canvas, event_name, closure) ?;
0 commit comments