Skip to content

Commit d79fae5

Browse files
committed
Add warning about consume_shortcut and friends
1 parent 7b105cf commit d79fae5

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

crates/egui/src/input_state.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,11 @@ impl InputState {
290290
///
291291
/// Includes key-repeat events.
292292
///
293-
/// This uses [`Modifiers::matches_logically`] to match modifiers.
294-
/// This means that e.g. the shortcut `Ctrl` + `Key::Plus` will be matched
295-
/// as long as `Ctrl` and `Plus` are pressed, ignoring if
296-
/// `Shift` or `Alt` are also pressed (because those modifiers might
297-
/// be required to produce the logical `Key::Plus`).
293+
/// This uses [`Modifiers::matches_logically`] to match modifiers,
294+
/// meaning extra Shift and Alt modifiers are ignored.
295+
/// Therefore, you should match most specific shortcuts first,
296+
/// i.e. check for `Cmd-Shift-S` ("Save as…") before `Cmd-S` ("Save"),
297+
/// so that a user pressing `Cmd-Shift-S` won't trigger the wrong command!
298298
pub fn count_and_consume_key(&mut self, modifiers: Modifiers, logical_key: Key) -> usize {
299299
let mut count = 0usize;
300300

@@ -320,6 +320,12 @@ impl InputState {
320320
/// Check for a key press. If found, `true` is returned and the key pressed is consumed, so that this will only return `true` once.
321321
///
322322
/// Includes key-repeat events.
323+
///
324+
/// This uses [`Modifiers::matches_logically`] to match modifiers,
325+
/// meaning extra Shift and Alt modifiers are ignored.
326+
/// Therefore, you should match most specific shortcuts first,
327+
/// i.e. check for `Cmd-Shift-S` ("Save as…") before `Cmd-S` ("Save"),
328+
/// so that a user pressing `Cmd-Shift-S` won't trigger the wrong command!
323329
pub fn consume_key(&mut self, modifiers: Modifiers, logical_key: Key) -> bool {
324330
self.count_and_consume_key(modifiers, logical_key) > 0
325331
}
@@ -328,7 +334,11 @@ impl InputState {
328334
///
329335
/// If so, `true` is returned and the key pressed is consumed, so that this will only return `true` once.
330336
///
331-
/// Includes key-repeat events.
337+
/// This uses [`Modifiers::matches_logically`] to match modifiers,
338+
/// meaning extra Shift and Alt modifiers are ignored.
339+
/// Therefore, you should match most specific shortcuts first,
340+
/// i.e. check for `Cmd-Shift-S` ("Save as…") before `Cmd-S` ("Save"),
341+
/// so that a user pressing `Cmd-Shift-S` won't trigger the wrong command!
332342
pub fn consume_shortcut(&mut self, shortcut: &KeyboardShortcut) -> bool {
333343
let KeyboardShortcut {
334344
modifiers,

0 commit comments

Comments
 (0)