From 99641d2637b5c2418289d8c1168f35eb35ddc098 Mon Sep 17 00:00:00 2001 From: LagoLunatic Date: Thu, 28 Nov 2024 19:32:48 -0500 Subject: [PATCH] Fix auto-scrolling to highlighted symbol only working for the left side The flag is cleared after one scroll to avoid doing it continuously, but this breaks when we need to scroll to both the left and the right symbol at the same time. So now each side has its own flag to keep track of this state independently. --- objdiff-gui/src/views/function_diff.rs | 4 ++-- objdiff-gui/src/views/symbol_diff.rs | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/objdiff-gui/src/views/function_diff.rs b/objdiff-gui/src/views/function_diff.rs index fa97a65..d737471 100644 --- a/objdiff-gui/src/views/function_diff.rs +++ b/objdiff-gui/src/views/function_diff.rs @@ -519,7 +519,7 @@ fn asm_table_ui( } DiffViewAction::SetSymbolHighlight(left, right, scroll) => { symbol_state.highlighted_symbol = (left, right); - symbol_state.scroll_highlighted_symbol_into_view = scroll; + symbol_state.scroll_to_highlighted_symbols = (scroll, scroll); } _ => { ret = Some(action); @@ -581,7 +581,7 @@ fn asm_table_ui( } DiffViewAction::SetSymbolHighlight(left, right, scroll) => { symbol_state.highlighted_symbol = (left, right); - symbol_state.scroll_highlighted_symbol_into_view = scroll; + symbol_state.scroll_to_highlighted_symbols = (scroll, scroll); } _ => { ret = Some(action); diff --git a/objdiff-gui/src/views/symbol_diff.rs b/objdiff-gui/src/views/symbol_diff.rs index 0a9fb4a..a43cd86 100644 --- a/objdiff-gui/src/views/symbol_diff.rs +++ b/objdiff-gui/src/views/symbol_diff.rs @@ -136,7 +136,7 @@ pub struct DiffViewState { #[derive(Default)] pub struct SymbolViewState { pub highlighted_symbol: (Option, Option), - pub scroll_highlighted_symbol_into_view: bool, + pub scroll_to_highlighted_symbols: (bool, bool), pub left_symbol: Option, pub right_symbol: Option, pub reverse_fn_order: bool, @@ -250,7 +250,7 @@ impl DiffViewState { } DiffViewAction::SetSymbolHighlight(left, right, scroll) => { self.symbol_state.highlighted_symbol = (left, right); - self.symbol_state.scroll_highlighted_symbol_into_view = scroll; + self.symbol_state.scroll_to_highlighted_symbols = (scroll, scroll); } DiffViewAction::SetSearch(search) => { self.search_regex = if search.is_empty() { @@ -536,13 +536,18 @@ fn symbol_ui( ret = Some(DiffViewAction::Navigate(result)); } }); - if selected && state.scroll_highlighted_symbol_into_view { + let should_scroll = if column == 0 { + &mut state.scroll_to_highlighted_symbols.0 + } else { + &mut state.scroll_to_highlighted_symbols.1 + }; + if selected && *should_scroll { // Scroll the view to encompass the selected symbol in case the user selected an offscreen // symbol by using a keyboard shortcut. ui.scroll_to_rect_animation(response.rect, None, ScrollAnimation::none()); // Then reset this flag so that we don't repeatedly scroll the view back when the user is // trying to manually scroll away. - state.scroll_highlighted_symbol_into_view = false; + *should_scroll = false; } if response.clicked() || (selected && hotkeys::enter_pressed(ui.ctx())) { if let Some(section) = section {