Skip to content

Commit 5de087c

Browse files
committed
Fix some hotkeys stealing input from focused widgets
e.g. The symbol list was stealing the W/S key presses when typing into the symbol filter text edit. If the user actually wants to use these shortcuts while a widget is focused, they can simply press the escape key to unfocus all widgets and then press the shortcut.
1 parent 5af40e0 commit 5de087c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

objdiff-gui/src/hotkeys.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
use egui::{style::ScrollAnimation, vec2, Context, Key, Modifiers, PointerButton};
22

3+
fn any_widget_focused(ctx: &Context) -> bool { ctx.memory(|mem| mem.focused().is_some()) }
4+
35
pub fn enter_pressed(ctx: &Context) -> bool {
6+
if any_widget_focused(ctx) {
7+
return false;
8+
}
49
ctx.input_mut(|i| i.key_pressed(Key::Enter) || i.pointer.button_pressed(PointerButton::Extra2))
510
}
611

712
pub fn back_pressed(ctx: &Context) -> bool {
13+
if any_widget_focused(ctx) {
14+
return false;
15+
}
816
ctx.input_mut(|i| {
917
i.key_pressed(Key::Backspace) || i.pointer.button_pressed(PointerButton::Extra1)
1018
})
1119
}
1220

1321
pub fn up_pressed(ctx: &Context) -> bool {
22+
if any_widget_focused(ctx) {
23+
return false;
24+
}
1425
ctx.input_mut(|i| i.key_pressed(Key::ArrowUp) || i.key_pressed(Key::W))
1526
}
1627

1728
pub fn down_pressed(ctx: &Context) -> bool {
29+
if any_widget_focused(ctx) {
30+
return false;
31+
}
1832
ctx.input_mut(|i| i.key_pressed(Key::ArrowDown) || i.key_pressed(Key::S))
1933
}
2034

@@ -44,12 +58,18 @@ pub fn check_scroll_hotkeys(ui: &mut egui::Ui, include_small_increments: bool) {
4458
}
4559

4660
pub fn consume_up_key(ctx: &Context) -> bool {
61+
if any_widget_focused(ctx) {
62+
return false;
63+
}
4764
ctx.input_mut(|i| {
4865
i.consume_key(Modifiers::NONE, Key::ArrowUp) || i.consume_key(Modifiers::NONE, Key::W)
4966
})
5067
}
5168

5269
pub fn consume_down_key(ctx: &Context) -> bool {
70+
if any_widget_focused(ctx) {
71+
return false;
72+
}
5373
ctx.input_mut(|i| {
5474
i.consume_key(Modifiers::NONE, Key::ArrowDown) || i.consume_key(Modifiers::NONE, Key::S)
5575
})

0 commit comments

Comments
 (0)