Skip to content

Commit 446dd68

Browse files
committed
Simplify clearing of the autoscroll flag, remove &mut State
1 parent 99641d2 commit 446dd68

File tree

3 files changed

+17
-29
lines changed

3 files changed

+17
-29
lines changed

objdiff-gui/src/app.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,8 @@ impl eframe::App for App {
831831
} else {
832832
symbol_diff_ui(ui, diff_state, appearance)
833833
};
834+
// Clear the autoscroll flag so it doesn't scroll continuously.
835+
diff_state.symbol_state.autoscroll_to_highlighted_symbols = false;
834836
});
835837

836838
project_window(ctx, state, show_project_config, config_state, appearance);

objdiff-gui/src/views/function_diff.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ fn asm_table_ui(
409409
right_ctx: Option<FunctionDiffContext<'_>>,
410410
appearance: &Appearance,
411411
ins_view_state: &FunctionViewState,
412-
symbol_state: &mut SymbolViewState,
412+
symbol_state: &SymbolViewState,
413413
) -> Option<DiffViewAction> {
414414
let mut ret = None;
415415
let left_len = left_ctx.and_then(|ctx| {
@@ -517,10 +517,6 @@ fn asm_table_ui(
517517
SymbolRefByName::new(right_symbol, right_section),
518518
));
519519
}
520-
DiffViewAction::SetSymbolHighlight(left, right, scroll) => {
521-
symbol_state.highlighted_symbol = (left, right);
522-
symbol_state.scroll_to_highlighted_symbols = (scroll, scroll);
523-
}
524520
_ => {
525521
ret = Some(action);
526522
}
@@ -579,10 +575,6 @@ fn asm_table_ui(
579575
right_symbol_ref,
580576
));
581577
}
582-
DiffViewAction::SetSymbolHighlight(left, right, scroll) => {
583-
symbol_state.highlighted_symbol = (left, right);
584-
symbol_state.scroll_to_highlighted_symbols = (scroll, scroll);
585-
}
586578
_ => {
587579
ret = Some(action);
588580
}
@@ -624,7 +616,7 @@ impl<'a> FunctionDiffContext<'a> {
624616
#[must_use]
625617
pub fn function_diff_ui(
626618
ui: &mut egui::Ui,
627-
state: &mut DiffViewState,
619+
state: &DiffViewState,
628620
appearance: &Appearance,
629621
) -> Option<DiffViewAction> {
630622
let mut ret = None;
@@ -829,7 +821,7 @@ pub fn function_diff_ui(
829821
right_ctx,
830822
appearance,
831823
&state.function_state,
832-
&mut state.symbol_state,
824+
&state.symbol_state,
833825
)
834826
})
835827
.inner

objdiff-gui/src/views/symbol_diff.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub struct DiffViewState {
136136
#[derive(Default)]
137137
pub struct SymbolViewState {
138138
pub highlighted_symbol: (Option<SymbolRef>, Option<SymbolRef>),
139-
pub scroll_to_highlighted_symbols: (bool, bool),
139+
pub autoscroll_to_highlighted_symbols: bool,
140140
pub left_symbol: Option<SymbolRefByName>,
141141
pub right_symbol: Option<SymbolRefByName>,
142142
pub reverse_fn_order: bool,
@@ -248,9 +248,9 @@ impl DiffViewState {
248248
self.post_build_nav = Some(nav);
249249
}
250250
}
251-
DiffViewAction::SetSymbolHighlight(left, right, scroll) => {
251+
DiffViewAction::SetSymbolHighlight(left, right, autoscroll) => {
252252
self.symbol_state.highlighted_symbol = (left, right);
253-
self.symbol_state.scroll_to_highlighted_symbols = (scroll, scroll);
253+
self.symbol_state.autoscroll_to_highlighted_symbols = autoscroll;
254254
}
255255
DiffViewAction::SetSearch(search) => {
256256
self.search_regex = if search.is_empty() {
@@ -473,7 +473,7 @@ fn symbol_ui(
473473
symbol: &ObjSymbol,
474474
symbol_diff: &ObjSymbolDiff,
475475
section: Option<&ObjSection>,
476-
state: &mut SymbolViewState,
476+
state: &SymbolViewState,
477477
appearance: &Appearance,
478478
column: usize,
479479
) -> Option<DiffViewAction> {
@@ -536,18 +536,12 @@ fn symbol_ui(
536536
ret = Some(DiffViewAction::Navigate(result));
537537
}
538538
});
539-
let should_scroll = if column == 0 {
540-
&mut state.scroll_to_highlighted_symbols.0
541-
} else {
542-
&mut state.scroll_to_highlighted_symbols.1
543-
};
544-
if selected && *should_scroll {
545-
// Scroll the view to encompass the selected symbol in case the user selected an offscreen
546-
// symbol by using a keyboard shortcut.
539+
if selected && state.autoscroll_to_highlighted_symbols {
540+
// Automatically scroll the view to encompass the selected symbol in case the user selected
541+
// an offscreen symbol by using a keyboard shortcut.
547542
ui.scroll_to_rect_animation(response.rect, None, ScrollAnimation::none());
548-
// Then reset this flag so that we don't repeatedly scroll the view back when the user is
549-
// trying to manually scroll away.
550-
*should_scroll = false;
543+
// This state flag will be reset in App::update at the end of every frame so that we don't
544+
// continuously scroll the view back when the user is trying to manually scroll away.
551545
}
552546
if response.clicked() || (selected && hotkeys::enter_pressed(ui.ctx())) {
553547
if let Some(section) = section {
@@ -620,7 +614,7 @@ pub fn symbol_list_ui(
620614
ui: &mut Ui,
621615
ctx: SymbolDiffContext<'_>,
622616
other_ctx: Option<SymbolDiffContext<'_>>,
623-
state: &mut SymbolViewState,
617+
state: &SymbolViewState,
624618
filter: SymbolFilter<'_>,
625619
appearance: &Appearance,
626620
column: usize,
@@ -964,7 +958,7 @@ pub fn symbol_diff_ui(
964958
.second_obj
965959
.as_ref()
966960
.map(|(obj, diff)| SymbolDiffContext { obj, diff }),
967-
&mut state.symbol_state,
961+
&state.symbol_state,
968962
filter,
969963
appearance,
970964
column,
@@ -988,7 +982,7 @@ pub fn symbol_diff_ui(
988982
.first_obj
989983
.as_ref()
990984
.map(|(obj, diff)| SymbolDiffContext { obj, diff }),
991-
&mut state.symbol_state,
985+
&state.symbol_state,
992986
filter,
993987
appearance,
994988
column,

0 commit comments

Comments
 (0)