Add KeyboardShortcut::conflicts_with_text_editing (#8536)

Moved over from Rerun

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Emil ErnerfeldtandClaude Fable 5.1 authored and GitHub committed 2026-09-21 10:30:38 +02:00
1 parent c95e3d14c0
commit e303ab7e14
1 file changed
+30
@@ -34,6 +34,36 @@ impl KeyboardShortcut {
}
s
}
/// Would consuming this shortcut interfere with editing text
/// (e.g. moving the text cursor, or typing a space)?
///
/// This is true for any shortcut without modifiers (e.g. `Space`, `A`, `Delete`),
/// as well as for shortcuts using keys that are commonly combined with modifiers
/// when editing text (e.g. `Alt+ArrowLeft` to move one word, or `Shift+Home` to select to the start of a line).
///
/// Such shortcuts should only be consumed when no text field has keyboard focus.
/// See also [`crate::Memory::focused`] and [`crate::Context::egui_wants_keyboard_input`].
///
/// ```
/// # use egui::{Key, KeyboardShortcut, Modifiers};
/// assert!(KeyboardShortcut::new(Modifiers::NONE, Key::Space).conflicts_with_text_editing());
/// assert!(KeyboardShortcut::new(Modifiers::ALT, Key::ArrowLeft).conflicts_with_text_editing());
/// assert!(!KeyboardShortcut::new(Modifiers::COMMAND, Key::S).conflicts_with_text_editing());
/// ```
pub fn conflicts_with_text_editing(&self) -> bool {
self.modifiers.is_none()
|| matches!(
self.logical_key,
Key::Space
| Key::ArrowLeft
| Key::ArrowRight
| Key::ArrowUp
| Key::ArrowDown
| Key::Home
| Key::End
)
}
}
#[test]