Skip to content

Commit

Permalink
Fix auto-scrolling to highlighted symbol only working for the left side
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LagoLunatic committed Nov 29, 2024
1 parent d5dcc4f commit 99641d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions objdiff-gui/src/views/function_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 9 additions & 4 deletions objdiff-gui/src/views/symbol_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub struct DiffViewState {
#[derive(Default)]
pub struct SymbolViewState {
pub highlighted_symbol: (Option<SymbolRef>, Option<SymbolRef>),
pub scroll_highlighted_symbol_into_view: bool,
pub scroll_to_highlighted_symbols: (bool, bool),
pub left_symbol: Option<SymbolRefByName>,
pub right_symbol: Option<SymbolRefByName>,
pub reverse_fn_order: bool,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 99641d2

Please sign in to comment.