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.
This commit is contained in:
LagoLunatic 2024-11-28 19:32:48 -05:00
parent d5dcc4f00f
commit 99641d2637
2 changed files with 11 additions and 6 deletions

View File

@ -519,7 +519,7 @@ fn asm_table_ui(
} }
DiffViewAction::SetSymbolHighlight(left, right, scroll) => { DiffViewAction::SetSymbolHighlight(left, right, scroll) => {
symbol_state.highlighted_symbol = (left, right); 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); ret = Some(action);
@ -581,7 +581,7 @@ fn asm_table_ui(
} }
DiffViewAction::SetSymbolHighlight(left, right, scroll) => { DiffViewAction::SetSymbolHighlight(left, right, scroll) => {
symbol_state.highlighted_symbol = (left, right); 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); ret = Some(action);

View File

@ -136,7 +136,7 @@ pub struct DiffViewState {
#[derive(Default)] #[derive(Default)]
pub struct SymbolViewState { pub struct SymbolViewState {
pub highlighted_symbol: (Option<SymbolRef>, Option<SymbolRef>), 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 left_symbol: Option<SymbolRefByName>,
pub right_symbol: Option<SymbolRefByName>, pub right_symbol: Option<SymbolRefByName>,
pub reverse_fn_order: bool, pub reverse_fn_order: bool,
@ -250,7 +250,7 @@ impl DiffViewState {
} }
DiffViewAction::SetSymbolHighlight(left, right, scroll) => { DiffViewAction::SetSymbolHighlight(left, right, scroll) => {
self.symbol_state.highlighted_symbol = (left, right); 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) => { DiffViewAction::SetSearch(search) => {
self.search_regex = if search.is_empty() { self.search_regex = if search.is_empty() {
@ -536,13 +536,18 @@ fn symbol_ui(
ret = Some(DiffViewAction::Navigate(result)); 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 // Scroll the view to encompass the selected symbol in case the user selected an offscreen
// symbol by using a keyboard shortcut. // symbol by using a keyboard shortcut.
ui.scroll_to_rect_animation(response.rect, None, ScrollAnimation::none()); 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 // Then reset this flag so that we don't repeatedly scroll the view back when the user is
// trying to manually scroll away. // 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 response.clicked() || (selected && hotkeys::enter_pressed(ui.ctx())) {
if let Some(section) = section { if let Some(section) = section {