From 98e971d0ce8288b2d4ed7086312f143824b979c5 Mon Sep 17 00:00:00 2001 From: LagoLunatic Date: Thu, 28 Nov 2024 18:30:50 -0500 Subject: [PATCH] Add hotkeys to change target and base functions --- objdiff-gui/src/hotkeys.rs | 12 ++++++++++++ objdiff-gui/src/views/function_diff.rs | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/objdiff-gui/src/hotkeys.rs b/objdiff-gui/src/hotkeys.rs index 23151c0..72177b1 100644 --- a/objdiff-gui/src/hotkeys.rs +++ b/objdiff-gui/src/hotkeys.rs @@ -92,3 +92,15 @@ const SYMBOL_FILTER_SHORTCUT: KeyboardShortcut = KeyboardShortcut::new(Modifiers pub fn consume_symbol_filter_shortcut(ctx: &Context) -> bool { ctx.input_mut(|i| i.consume_shortcut(&SYMBOL_FILTER_SHORTCUT)) } + +const CHANGE_TARGET_SHORTCUT: KeyboardShortcut = KeyboardShortcut::new(Modifiers::CTRL, Key::T); + +pub fn consume_change_target_shortcut(ctx: &Context) -> bool { + ctx.input_mut(|i| i.consume_shortcut(&CHANGE_TARGET_SHORTCUT)) +} + +const CHANGE_BASE_SHORTCUT: KeyboardShortcut = KeyboardShortcut::new(Modifiers::CTRL, Key::B); + +pub fn consume_change_base_shortcut(ctx: &Context) -> bool { + ctx.input_mut(|i| i.consume_shortcut(&CHANGE_BASE_SHORTCUT)) +} diff --git a/objdiff-gui/src/views/function_diff.rs b/objdiff-gui/src/views/function_diff.rs index 3344463..a3cdd8b 100644 --- a/objdiff-gui/src/views/function_diff.rs +++ b/objdiff-gui/src/views/function_diff.rs @@ -714,10 +714,11 @@ pub fn function_diff_ui( .color(appearance.highlight_color), ); if right_ctx.map_or(false, |m| m.has_symbol()) - && ui + && (ui .button("Change target") .on_hover_text_at_pointer("Choose a different symbol to use as the target") .clicked() + || hotkeys::consume_change_target_shortcut(ui.ctx())) { if let Some(symbol_ref) = state.symbol_state.right_symbol.as_ref() { ret = Some(DiffViewAction::SelectingLeft(symbol_ref.clone())); @@ -791,6 +792,7 @@ pub fn function_diff_ui( "Choose a different symbol to use as the base", ) .clicked() + || hotkeys::consume_change_base_shortcut(ui.ctx()) { if let Some(symbol_ref) = state.symbol_state.left_symbol.as_ref() { ret = Some(DiffViewAction::SelectingRight(symbol_ref.clone()));