mirror of https://github.com/encounter/objdiff.git
Simplify clearing of the autoscroll flag, remove &mut State
This commit is contained in:
parent
99641d2637
commit
446dd68328
|
@ -831,6 +831,8 @@ impl eframe::App for App {
|
||||||
} else {
|
} else {
|
||||||
symbol_diff_ui(ui, diff_state, appearance)
|
symbol_diff_ui(ui, diff_state, appearance)
|
||||||
};
|
};
|
||||||
|
// Clear the autoscroll flag so it doesn't scroll continuously.
|
||||||
|
diff_state.symbol_state.autoscroll_to_highlighted_symbols = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
project_window(ctx, state, show_project_config, config_state, appearance);
|
project_window(ctx, state, show_project_config, config_state, appearance);
|
||||||
|
|
|
@ -409,7 +409,7 @@ fn asm_table_ui(
|
||||||
right_ctx: Option<FunctionDiffContext<'_>>,
|
right_ctx: Option<FunctionDiffContext<'_>>,
|
||||||
appearance: &Appearance,
|
appearance: &Appearance,
|
||||||
ins_view_state: &FunctionViewState,
|
ins_view_state: &FunctionViewState,
|
||||||
symbol_state: &mut SymbolViewState,
|
symbol_state: &SymbolViewState,
|
||||||
) -> Option<DiffViewAction> {
|
) -> Option<DiffViewAction> {
|
||||||
let mut ret = None;
|
let mut ret = None;
|
||||||
let left_len = left_ctx.and_then(|ctx| {
|
let left_len = left_ctx.and_then(|ctx| {
|
||||||
|
@ -517,10 +517,6 @@ fn asm_table_ui(
|
||||||
SymbolRefByName::new(right_symbol, right_section),
|
SymbolRefByName::new(right_symbol, right_section),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
DiffViewAction::SetSymbolHighlight(left, right, scroll) => {
|
|
||||||
symbol_state.highlighted_symbol = (left, right);
|
|
||||||
symbol_state.scroll_to_highlighted_symbols = (scroll, scroll);
|
|
||||||
}
|
|
||||||
_ => {
|
_ => {
|
||||||
ret = Some(action);
|
ret = Some(action);
|
||||||
}
|
}
|
||||||
|
@ -579,10 +575,6 @@ fn asm_table_ui(
|
||||||
right_symbol_ref,
|
right_symbol_ref,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
DiffViewAction::SetSymbolHighlight(left, right, scroll) => {
|
|
||||||
symbol_state.highlighted_symbol = (left, right);
|
|
||||||
symbol_state.scroll_to_highlighted_symbols = (scroll, scroll);
|
|
||||||
}
|
|
||||||
_ => {
|
_ => {
|
||||||
ret = Some(action);
|
ret = Some(action);
|
||||||
}
|
}
|
||||||
|
@ -624,7 +616,7 @@ impl<'a> FunctionDiffContext<'a> {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn function_diff_ui(
|
pub fn function_diff_ui(
|
||||||
ui: &mut egui::Ui,
|
ui: &mut egui::Ui,
|
||||||
state: &mut DiffViewState,
|
state: &DiffViewState,
|
||||||
appearance: &Appearance,
|
appearance: &Appearance,
|
||||||
) -> Option<DiffViewAction> {
|
) -> Option<DiffViewAction> {
|
||||||
let mut ret = None;
|
let mut ret = None;
|
||||||
|
@ -829,7 +821,7 @@ pub fn function_diff_ui(
|
||||||
right_ctx,
|
right_ctx,
|
||||||
appearance,
|
appearance,
|
||||||
&state.function_state,
|
&state.function_state,
|
||||||
&mut state.symbol_state,
|
&state.symbol_state,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.inner
|
.inner
|
||||||
|
|
|
@ -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_to_highlighted_symbols: (bool, bool),
|
pub autoscroll_to_highlighted_symbols: 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,
|
||||||
|
@ -248,9 +248,9 @@ impl DiffViewState {
|
||||||
self.post_build_nav = Some(nav);
|
self.post_build_nav = Some(nav);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DiffViewAction::SetSymbolHighlight(left, right, scroll) => {
|
DiffViewAction::SetSymbolHighlight(left, right, autoscroll) => {
|
||||||
self.symbol_state.highlighted_symbol = (left, right);
|
self.symbol_state.highlighted_symbol = (left, right);
|
||||||
self.symbol_state.scroll_to_highlighted_symbols = (scroll, scroll);
|
self.symbol_state.autoscroll_to_highlighted_symbols = autoscroll;
|
||||||
}
|
}
|
||||||
DiffViewAction::SetSearch(search) => {
|
DiffViewAction::SetSearch(search) => {
|
||||||
self.search_regex = if search.is_empty() {
|
self.search_regex = if search.is_empty() {
|
||||||
|
@ -473,7 +473,7 @@ fn symbol_ui(
|
||||||
symbol: &ObjSymbol,
|
symbol: &ObjSymbol,
|
||||||
symbol_diff: &ObjSymbolDiff,
|
symbol_diff: &ObjSymbolDiff,
|
||||||
section: Option<&ObjSection>,
|
section: Option<&ObjSection>,
|
||||||
state: &mut SymbolViewState,
|
state: &SymbolViewState,
|
||||||
appearance: &Appearance,
|
appearance: &Appearance,
|
||||||
column: usize,
|
column: usize,
|
||||||
) -> Option<DiffViewAction> {
|
) -> Option<DiffViewAction> {
|
||||||
|
@ -536,18 +536,12 @@ fn symbol_ui(
|
||||||
ret = Some(DiffViewAction::Navigate(result));
|
ret = Some(DiffViewAction::Navigate(result));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let should_scroll = if column == 0 {
|
if selected && state.autoscroll_to_highlighted_symbols {
|
||||||
&mut state.scroll_to_highlighted_symbols.0
|
// Automatically scroll the view to encompass the selected symbol in case the user selected
|
||||||
} else {
|
// an offscreen symbol by using a keyboard shortcut.
|
||||||
&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());
|
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
|
// This state flag will be reset in App::update at the end of every frame so that we don't
|
||||||
// trying to manually scroll away.
|
// continuously scroll the view back when the user is trying to manually scroll away.
|
||||||
*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 {
|
||||||
|
@ -620,7 +614,7 @@ pub fn symbol_list_ui(
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
ctx: SymbolDiffContext<'_>,
|
ctx: SymbolDiffContext<'_>,
|
||||||
other_ctx: Option<SymbolDiffContext<'_>>,
|
other_ctx: Option<SymbolDiffContext<'_>>,
|
||||||
state: &mut SymbolViewState,
|
state: &SymbolViewState,
|
||||||
filter: SymbolFilter<'_>,
|
filter: SymbolFilter<'_>,
|
||||||
appearance: &Appearance,
|
appearance: &Appearance,
|
||||||
column: usize,
|
column: usize,
|
||||||
|
@ -964,7 +958,7 @@ pub fn symbol_diff_ui(
|
||||||
.second_obj
|
.second_obj
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|(obj, diff)| SymbolDiffContext { obj, diff }),
|
.map(|(obj, diff)| SymbolDiffContext { obj, diff }),
|
||||||
&mut state.symbol_state,
|
&state.symbol_state,
|
||||||
filter,
|
filter,
|
||||||
appearance,
|
appearance,
|
||||||
column,
|
column,
|
||||||
|
@ -988,7 +982,7 @@ pub fn symbol_diff_ui(
|
||||||
.first_obj
|
.first_obj
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|(obj, diff)| SymbolDiffContext { obj, diff }),
|
.map(|(obj, diff)| SymbolDiffContext { obj, diff }),
|
||||||
&mut state.symbol_state,
|
&state.symbol_state,
|
||||||
filter,
|
filter,
|
||||||
appearance,
|
appearance,
|
||||||
column,
|
column,
|
||||||
|
|
Loading…
Reference in New Issue