diff --git a/objdiff-gui/src/hotkeys.rs b/objdiff-gui/src/hotkeys.rs new file mode 100644 index 0000000..762e5db --- /dev/null +++ b/objdiff-gui/src/hotkeys.rs @@ -0,0 +1,11 @@ +use egui::{Context, Key, PointerButton}; + +pub fn enter_pressed(ctx: &Context) -> bool { + ctx.input_mut(|i| i.key_pressed(Key::Enter) || i.pointer.button_pressed(PointerButton::Extra2)) +} + +pub fn back_pressed(ctx: &Context) -> bool { + ctx.input_mut(|i| { + i.key_pressed(Key::Backspace) || i.pointer.button_pressed(PointerButton::Extra1) + }) +} diff --git a/objdiff-gui/src/main.rs b/objdiff-gui/src/main.rs index 18e6b7f..0974a00 100644 --- a/objdiff-gui/src/main.rs +++ b/objdiff-gui/src/main.rs @@ -4,6 +4,7 @@ mod app; mod app_config; mod config; mod fonts; +mod hotkeys; mod jobs; mod update; mod views; diff --git a/objdiff-gui/src/views/data_diff.rs b/objdiff-gui/src/views/data_diff.rs index 224a169..152b9ef 100644 --- a/objdiff-gui/src/views/data_diff.rs +++ b/objdiff-gui/src/views/data_diff.rs @@ -7,11 +7,14 @@ use objdiff_core::{ }; use time::format_description; -use crate::views::{ - appearance::Appearance, - column_layout::{render_header, render_table}, - symbol_diff::{DiffViewAction, DiffViewNavigation, DiffViewState}, - write_text, +use crate::{ + hotkeys, + views::{ + appearance::Appearance, + column_layout::{render_header, render_table}, + symbol_diff::{DiffViewAction, DiffViewNavigation, DiffViewState}, + write_text, + }, }; const BYTES_PER_ROW: usize = 16; @@ -224,7 +227,7 @@ pub fn data_diff_ui( render_header(ui, available_width, 2, |ui, column| { if column == 0 { // Left column - if ui.button("⏴ Back").clicked() { + if ui.button("⏴ Back").clicked() || hotkeys::back_pressed(ui.ctx()) { ret = Some(DiffViewAction::Navigate(DiffViewNavigation::symbol_diff())); } diff --git a/objdiff-gui/src/views/extab_diff.rs b/objdiff-gui/src/views/extab_diff.rs index b91cd62..952909f 100644 --- a/objdiff-gui/src/views/extab_diff.rs +++ b/objdiff-gui/src/views/extab_diff.rs @@ -5,13 +5,16 @@ use objdiff_core::{ }; use time::format_description; -use crate::views::{ - appearance::Appearance, - column_layout::{render_header, render_strips}, - function_diff::FunctionDiffContext, - symbol_diff::{ - match_color_for_symbol, DiffViewAction, DiffViewNavigation, DiffViewState, SymbolRefByName, - View, +use crate::{ + hotkeys, + views::{ + appearance::Appearance, + column_layout::{render_header, render_strips}, + function_diff::FunctionDiffContext, + symbol_diff::{ + match_color_for_symbol, DiffViewAction, DiffViewNavigation, DiffViewState, + SymbolRefByName, View, + }, }, }; @@ -136,7 +139,7 @@ pub fn extab_diff_ui( if column == 0 { // Left column ui.horizontal(|ui| { - if ui.button("⏴ Back").clicked() { + if ui.button("⏴ Back").clicked() || hotkeys::back_pressed(ui.ctx()) { ret = Some(DiffViewAction::Navigate(DiffViewNavigation::symbol_diff())); } ui.separator(); diff --git a/objdiff-gui/src/views/function_diff.rs b/objdiff-gui/src/views/function_diff.rs index 168ed7e..0be5745 100644 --- a/objdiff-gui/src/views/function_diff.rs +++ b/objdiff-gui/src/views/function_diff.rs @@ -14,12 +14,15 @@ use objdiff_core::{ }; use time::format_description; -use crate::views::{ - appearance::Appearance, - column_layout::{render_header, render_strips, render_table}, - symbol_diff::{ - match_color_for_symbol, symbol_list_ui, DiffViewAction, DiffViewNavigation, DiffViewState, - SymbolDiffContext, SymbolFilter, SymbolRefByName, SymbolViewState, View, +use crate::{ + hotkeys, + views::{ + appearance::Appearance, + column_layout::{render_header, render_strips, render_table}, + symbol_diff::{ + match_color_for_symbol, symbol_list_ui, DiffViewAction, DiffViewNavigation, + DiffViewState, SymbolDiffContext, SymbolFilter, SymbolRefByName, SymbolViewState, View, + }, }, }; @@ -675,7 +678,7 @@ pub fn function_diff_ui( if column == 0 { // Left column ui.horizontal(|ui| { - if ui.button("⏴ Back").clicked() { + if ui.button("⏴ Back").clicked() || hotkeys::back_pressed(ui.ctx()) { ret = Some(DiffViewAction::Navigate(DiffViewNavigation::symbol_diff())); } ui.separator(); diff --git a/objdiff-gui/src/views/symbol_diff.rs b/objdiff-gui/src/views/symbol_diff.rs index 1ca66dd..1dca5de 100644 --- a/objdiff-gui/src/views/symbol_diff.rs +++ b/objdiff-gui/src/views/symbol_diff.rs @@ -15,6 +15,7 @@ use regex::{Regex, RegexBuilder}; use crate::{ app::AppStateRef, + hotkeys, jobs::{ create_scratch::{start_create_scratch, CreateScratchConfig, CreateScratchResult}, objdiff::{BuildStatus, ObjDiffResult}, @@ -534,7 +535,7 @@ fn symbol_ui( ret = Some(DiffViewAction::Navigate(result)); } }); - if response.clicked() { + if response.clicked() || (selected && hotkeys::enter_pressed(ui.ctx())) { if let Some(section) = section { match section.kind { ObjSectionKind::Code => {