mirror of https://github.com/encounter/objdiff.git
Auto-scroll the keyboard-selected symbols into view if offscreen
This commit is contained in:
parent
dfa145e16c
commit
5af40e0a33
|
@ -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: &SymbolViewState,
|
symbol_state: &mut 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| {
|
||||||
|
@ -516,8 +516,9 @@ fn asm_table_ui(
|
||||||
SymbolRefByName::new(right_symbol, right_section),
|
SymbolRefByName::new(right_symbol, right_section),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
DiffViewAction::SetSymbolHighlight(_, _) => {
|
DiffViewAction::SetSymbolHighlight(left, right, scroll) => {
|
||||||
// Ignore
|
symbol_state.highlighted_symbol = (left, right);
|
||||||
|
symbol_state.scroll_highlighted_symbol_into_view = scroll;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
ret = Some(action);
|
ret = Some(action);
|
||||||
|
@ -576,8 +577,9 @@ fn asm_table_ui(
|
||||||
right_symbol_ref,
|
right_symbol_ref,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
DiffViewAction::SetSymbolHighlight(_, _) => {
|
DiffViewAction::SetSymbolHighlight(left, right, scroll) => {
|
||||||
// Ignore
|
symbol_state.highlighted_symbol = (left, right);
|
||||||
|
symbol_state.scroll_highlighted_symbol_into_view = scroll;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
ret = Some(action);
|
ret = Some(action);
|
||||||
|
@ -620,7 +622,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: &DiffViewState,
|
state: &mut DiffViewState,
|
||||||
appearance: &Appearance,
|
appearance: &Appearance,
|
||||||
) -> Option<DiffViewAction> {
|
) -> Option<DiffViewAction> {
|
||||||
let mut ret = None;
|
let mut ret = None;
|
||||||
|
@ -823,7 +825,7 @@ pub fn function_diff_ui(
|
||||||
right_ctx,
|
right_ctx,
|
||||||
appearance,
|
appearance,
|
||||||
&state.function_state,
|
&state.function_state,
|
||||||
&state.symbol_state,
|
&mut state.symbol_state,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.inner
|
.inner
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use std::{collections::BTreeMap, mem::take, ops::Bound};
|
use std::{collections::BTreeMap, mem::take, ops::Bound};
|
||||||
|
|
||||||
use egui::{
|
use egui::{
|
||||||
text::LayoutJob, CollapsingHeader, Color32, Id, OpenUrl, ScrollArea, SelectableLabel, TextEdit,
|
style::ScrollAnimation, text::LayoutJob, CollapsingHeader, Color32, Id, OpenUrl, ScrollArea,
|
||||||
Ui, Widget,
|
SelectableLabel, TextEdit, Ui, Widget,
|
||||||
};
|
};
|
||||||
use objdiff_core::{
|
use objdiff_core::{
|
||||||
arch::ObjArch,
|
arch::ObjArch,
|
||||||
|
@ -57,8 +57,8 @@ pub enum DiffViewAction {
|
||||||
Build,
|
Build,
|
||||||
/// Navigate to a new diff view
|
/// Navigate to a new diff view
|
||||||
Navigate(DiffViewNavigation),
|
Navigate(DiffViewNavigation),
|
||||||
/// Set the highlighted symbols in the symbols view
|
/// Set the highlighted symbols in the symbols view, optionally scrolling them into view.
|
||||||
SetSymbolHighlight(Option<SymbolRef>, Option<SymbolRef>),
|
SetSymbolHighlight(Option<SymbolRef>, Option<SymbolRef>, bool),
|
||||||
/// Set the symbols view search filter
|
/// Set the symbols view search filter
|
||||||
SetSearch(String),
|
SetSearch(String),
|
||||||
/// Submit the current function to decomp.me
|
/// Submit the current function to decomp.me
|
||||||
|
@ -136,6 +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 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,
|
||||||
|
@ -247,8 +248,9 @@ impl DiffViewState {
|
||||||
self.post_build_nav = Some(nav);
|
self.post_build_nav = Some(nav);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DiffViewAction::SetSymbolHighlight(left, right) => {
|
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;
|
||||||
}
|
}
|
||||||
DiffViewAction::SetSearch(search) => {
|
DiffViewAction::SetSearch(search) => {
|
||||||
self.search_regex = if search.is_empty() {
|
self.search_regex = if search.is_empty() {
|
||||||
|
@ -471,7 +473,7 @@ fn symbol_ui(
|
||||||
symbol: &ObjSymbol,
|
symbol: &ObjSymbol,
|
||||||
symbol_diff: &ObjSymbolDiff,
|
symbol_diff: &ObjSymbolDiff,
|
||||||
section: Option<&ObjSection>,
|
section: Option<&ObjSection>,
|
||||||
state: &SymbolViewState,
|
state: &mut SymbolViewState,
|
||||||
appearance: &Appearance,
|
appearance: &Appearance,
|
||||||
column: usize,
|
column: usize,
|
||||||
) -> Option<DiffViewAction> {
|
) -> Option<DiffViewAction> {
|
||||||
|
@ -534,6 +536,14 @@ fn symbol_ui(
|
||||||
ret = Some(DiffViewAction::Navigate(result));
|
ret = Some(DiffViewAction::Navigate(result));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if selected && state.scroll_highlighted_symbol_into_view {
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
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 {
|
||||||
match section.kind {
|
match section.kind {
|
||||||
|
@ -565,11 +575,13 @@ fn symbol_ui(
|
||||||
DiffViewAction::SetSymbolHighlight(
|
DiffViewAction::SetSymbolHighlight(
|
||||||
Some(symbol_diff.symbol_ref),
|
Some(symbol_diff.symbol_ref),
|
||||||
symbol_diff.target_symbol,
|
symbol_diff.target_symbol,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
DiffViewAction::SetSymbolHighlight(
|
DiffViewAction::SetSymbolHighlight(
|
||||||
symbol_diff.target_symbol,
|
symbol_diff.target_symbol,
|
||||||
Some(symbol_diff.symbol_ref),
|
Some(symbol_diff.symbol_ref),
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -603,7 +615,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: &SymbolViewState,
|
state: &mut SymbolViewState,
|
||||||
filter: SymbolFilter<'_>,
|
filter: SymbolFilter<'_>,
|
||||||
appearance: &Appearance,
|
appearance: &Appearance,
|
||||||
column: usize,
|
column: usize,
|
||||||
|
@ -685,11 +697,13 @@ pub fn symbol_list_ui(
|
||||||
DiffViewAction::SetSymbolHighlight(
|
DiffViewAction::SetSymbolHighlight(
|
||||||
Some(*new_sym_ref),
|
Some(*new_sym_ref),
|
||||||
new_symbol_diff.target_symbol,
|
new_symbol_diff.target_symbol,
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
DiffViewAction::SetSymbolHighlight(
|
DiffViewAction::SetSymbolHighlight(
|
||||||
new_symbol_diff.target_symbol,
|
new_symbol_diff.target_symbol,
|
||||||
Some(*new_sym_ref),
|
Some(*new_sym_ref),
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -941,7 +955,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 }),
|
||||||
&state.symbol_state,
|
&mut state.symbol_state,
|
||||||
filter,
|
filter,
|
||||||
appearance,
|
appearance,
|
||||||
column,
|
column,
|
||||||
|
@ -965,7 +979,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 }),
|
||||||
&state.symbol_state,
|
&mut state.symbol_state,
|
||||||
filter,
|
filter,
|
||||||
appearance,
|
appearance,
|
||||||
column,
|
column,
|
||||||
|
|
Loading…
Reference in New Issue