fix: diff view search nav
This commit is contained in:
@@ -46,6 +46,7 @@ struct DiffSearchResult {
|
||||
|
||||
struct DiffSearchResultCursor {
|
||||
side: util::diff::DiffSide,
|
||||
diff_line_i: DiffLineIndex,
|
||||
index: usize,
|
||||
}
|
||||
|
||||
@@ -292,11 +293,13 @@ impl PullRequestDiffView {
|
||||
let cursor = if !old_search_result.is_empty() {
|
||||
DiffSearchResultCursor {
|
||||
side: util::diff::DiffSide::Old,
|
||||
diff_line_i: old_search_result[0].diff_line_i,
|
||||
index: 0,
|
||||
}
|
||||
} else {
|
||||
DiffSearchResultCursor {
|
||||
side: util::diff::DiffSide::New,
|
||||
diff_line_i: new_search_result[0].diff_line_i,
|
||||
index: 0,
|
||||
}
|
||||
};
|
||||
@@ -321,28 +324,11 @@ impl PullRequestDiffView {
|
||||
let theme = app::current_theme(cx);
|
||||
|
||||
let (current_side, other_side) = match search_result.cursor.side {
|
||||
| util::diff::DiffSide::Old => {
|
||||
// clear current cursor highlight
|
||||
// by replacing it with the normal styled highlighted range
|
||||
if let Some(mut highlights) = diff_view_state.old_side_highlights_mut() {
|
||||
highlights.replace_highlight_range(
|
||||
&search_result.old_side[search_result.cursor.index].highlight_range,
|
||||
);
|
||||
}
|
||||
(&search_result.old_side, &search_result.new_side)
|
||||
}
|
||||
| util::diff::DiffSide::New => {
|
||||
// clear current cursor highlight
|
||||
// by replacing it with the normal styled highlighted range
|
||||
if let Some(mut highlights) = diff_view_state.new_side_highlights_mut() {
|
||||
highlights.replace_highlight_range(
|
||||
&search_result.new_side[search_result.cursor.index].highlight_range,
|
||||
);
|
||||
}
|
||||
(&search_result.new_side, &search_result.old_side)
|
||||
}
|
||||
| util::diff::DiffSide::Old => (&search_result.old_side, &search_result.new_side),
|
||||
| util::diff::DiffSide::New => (&search_result.new_side, &search_result.old_side),
|
||||
};
|
||||
|
||||
let prev_side = search_result.cursor.side;
|
||||
let current_search_hit = ¤t_side[search_result.cursor.index];
|
||||
|
||||
let highlight_range = match current_side.get(search_result.cursor.index + 1) {
|
||||
@@ -396,10 +382,20 @@ impl PullRequestDiffView {
|
||||
i += 1;
|
||||
}
|
||||
|
||||
if let Some((_, other_side_i, r)) = other_side_result {
|
||||
// next cursor should be on other side with the found index
|
||||
search_result.cursor.side = search_result.cursor.side.flipped();
|
||||
search_result.cursor.index = other_side_i;
|
||||
if let Some((diff_line_i, other_side_i, r)) = other_side_result {
|
||||
if next_highlight_line == diff_line_i
|
||||
&& matches!(search_result.cursor.side, util::diff::DiffSide::Old)
|
||||
{
|
||||
// there is a hit on new side on same diff line as the next hit on old side
|
||||
// go to old side first
|
||||
search_result.cursor.diff_line_i = diff_line_i;
|
||||
search_result.cursor.index += 1;
|
||||
} else {
|
||||
// next cursor should be on other side with the found index
|
||||
search_result.cursor.side = search_result.cursor.side.flipped();
|
||||
search_result.cursor.diff_line_i = diff_line_i;
|
||||
search_result.cursor.index = other_side_i;
|
||||
}
|
||||
Some((
|
||||
r.clone(),
|
||||
gpui::HighlightStyle {
|
||||
@@ -424,6 +420,16 @@ impl PullRequestDiffView {
|
||||
};
|
||||
|
||||
if let Some(highlight_range) = highlight_range {
|
||||
{
|
||||
let prev_highlighted_content = match prev_side {
|
||||
| util::diff::DiffSide::Old => diff_view_state.old_side_highlights_mut(),
|
||||
| util::diff::DiffSide::New => diff_view_state.new_side_highlights_mut(),
|
||||
};
|
||||
if let Some(mut content) = prev_highlighted_content {
|
||||
content.replace_highlight_range(¤t_search_hit.highlight_range);
|
||||
}
|
||||
}
|
||||
|
||||
let content = match search_result.cursor.side {
|
||||
| util::diff::DiffSide::Old => diff_view_state.old_side_highlights_mut(),
|
||||
| util::diff::DiffSide::New => diff_view_state.new_side_highlights_mut(),
|
||||
@@ -433,6 +439,9 @@ impl PullRequestDiffView {
|
||||
}
|
||||
}
|
||||
|
||||
self.diff_view_state
|
||||
.scroll_to_diff_line(search_result.cursor.diff_line_i);
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user