Skip to content

Commit 08ebea8

Browse files
authored
Fix the symbol filter not working in the mapping view (#315)
* Fix the symbol filter not working in the mapping view * Separate the mapping filter from the regular filter * Make set/get search function names consistent with each other
1 parent 46b8890 commit 08ebea8

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

objdiff-gui/src/views/diff.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ pub fn diff_view_ui(
290290
});
291291
} else if left_ctx.status.success && !left_ctx.has_symbol() {
292292
ui.horizontal(|ui| {
293-
let mut search = state.search.clone();
293+
let mut search = state.get_current_search();
294294
let response =
295295
TextEdit::singleline(&mut search).hint_text("Filter symbols").ui(ui);
296296
if hotkeys::consume_symbol_filter_shortcut(ui.ctx()) {
@@ -480,7 +480,7 @@ pub fn diff_view_ui(
480480
}
481481
}
482482
} else if right_ctx.status.success && !right_ctx.has_symbol() {
483-
let mut search = state.search.clone();
483+
let mut search = state.get_current_search();
484484
let response =
485485
TextEdit::singleline(&mut search).hint_text("Filter symbols").ui(ui);
486486
if hotkeys::consume_symbol_filter_shortcut(ui.ctx()) {
@@ -827,7 +827,7 @@ fn diff_col_ui(
827827
ui,
828828
SymbolDiffContext { obj, diff },
829829
&state.symbol_state,
830-
SymbolFilter::Mapping(other_symbol_idx, None),
830+
SymbolFilter::Mapping(other_symbol_idx, state.mapping_search_regex.as_ref()),
831831
appearance,
832832
column,
833833
open_sections,

objdiff-gui/src/views/symbol_diff.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ pub struct DiffViewState {
118118
pub function_state: FunctionViewState,
119119
pub search: String,
120120
pub search_regex: Option<Regex>,
121+
pub mapping_search: String,
122+
pub mapping_search_regex: Option<Regex>,
121123
pub scroll_to_diff_row: Option<usize>,
122124
pub build_running: bool,
123125
pub scratch_available: bool,
@@ -155,6 +157,9 @@ impl DiffViewState {
155157
self.current_view = result.view;
156158
self.symbol_state.left_symbol = result.left_symbol;
157159
self.symbol_state.right_symbol = result.right_symbol;
160+
// Clear the mapping filter so it's not saved between mapping different symbols.
161+
self.mapping_search = "".to_string();
162+
self.mapping_search_regex = None;
158163
}
159164

160165
false
@@ -269,12 +274,7 @@ impl DiffViewState {
269274
self.symbol_state.autoscroll_to_highlighted_symbols = autoscroll;
270275
}
271276
DiffViewAction::SetSearch(search) => {
272-
self.search_regex = if search.is_empty() {
273-
None
274-
} else {
275-
RegexBuilder::new(&search).case_insensitive(true).build().ok()
276-
};
277-
self.search = search;
277+
self.set_current_search(search);
278278
}
279279
DiffViewAction::CreateScratch(function_name) => {
280280
let Ok(state) = state.read() else {
@@ -395,6 +395,29 @@ impl DiffViewState {
395395
target_symbol: symbol_diff.target_symbol,
396396
})
397397
}
398+
399+
pub fn get_current_search(&self) -> String {
400+
if self.current_view == View::FunctionDiff {
401+
self.mapping_search.clone()
402+
} else {
403+
self.search.clone()
404+
}
405+
}
406+
407+
fn set_current_search(&mut self, search: String) {
408+
let search_regex = if search.is_empty() {
409+
None
410+
} else {
411+
RegexBuilder::new(&search).case_insensitive(true).build().ok()
412+
};
413+
if self.current_view == View::FunctionDiff {
414+
self.mapping_search = search;
415+
self.mapping_search_regex = search_regex;
416+
} else {
417+
self.search = search;
418+
self.search_regex = search_regex;
419+
}
420+
}
398421
}
399422

400423
struct ResolvedSymbol<'obj> {

0 commit comments

Comments
 (0)