fix: diff view search nav
This commit is contained in:
@@ -46,6 +46,7 @@ struct DiffSearchResult {
|
|||||||
|
|
||||||
struct DiffSearchResultCursor {
|
struct DiffSearchResultCursor {
|
||||||
side: util::diff::DiffSide,
|
side: util::diff::DiffSide,
|
||||||
|
diff_line_i: DiffLineIndex,
|
||||||
index: usize,
|
index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,11 +293,13 @@ impl PullRequestDiffView {
|
|||||||
let cursor = if !old_search_result.is_empty() {
|
let cursor = if !old_search_result.is_empty() {
|
||||||
DiffSearchResultCursor {
|
DiffSearchResultCursor {
|
||||||
side: util::diff::DiffSide::Old,
|
side: util::diff::DiffSide::Old,
|
||||||
|
diff_line_i: old_search_result[0].diff_line_i,
|
||||||
index: 0,
|
index: 0,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DiffSearchResultCursor {
|
DiffSearchResultCursor {
|
||||||
side: util::diff::DiffSide::New,
|
side: util::diff::DiffSide::New,
|
||||||
|
diff_line_i: new_search_result[0].diff_line_i,
|
||||||
index: 0,
|
index: 0,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -321,28 +324,11 @@ impl PullRequestDiffView {
|
|||||||
let theme = app::current_theme(cx);
|
let theme = app::current_theme(cx);
|
||||||
|
|
||||||
let (current_side, other_side) = match search_result.cursor.side {
|
let (current_side, other_side) = match search_result.cursor.side {
|
||||||
| util::diff::DiffSide::Old => {
|
| util::diff::DiffSide::Old => (&search_result.old_side, &search_result.new_side),
|
||||||
// clear current cursor highlight
|
| util::diff::DiffSide::New => (&search_result.new_side, &search_result.old_side),
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let prev_side = search_result.cursor.side;
|
||||||
let current_search_hit = ¤t_side[search_result.cursor.index];
|
let current_search_hit = ¤t_side[search_result.cursor.index];
|
||||||
|
|
||||||
let highlight_range = match current_side.get(search_result.cursor.index + 1) {
|
let highlight_range = match current_side.get(search_result.cursor.index + 1) {
|
||||||
@@ -396,10 +382,20 @@ impl PullRequestDiffView {
|
|||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some((_, other_side_i, r)) = other_side_result {
|
if let Some((diff_line_i, other_side_i, r)) = other_side_result {
|
||||||
// next cursor should be on other side with the found index
|
if next_highlight_line == diff_line_i
|
||||||
search_result.cursor.side = search_result.cursor.side.flipped();
|
&& matches!(search_result.cursor.side, util::diff::DiffSide::Old)
|
||||||
search_result.cursor.index = other_side_i;
|
{
|
||||||
|
// 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((
|
Some((
|
||||||
r.clone(),
|
r.clone(),
|
||||||
gpui::HighlightStyle {
|
gpui::HighlightStyle {
|
||||||
@@ -424,6 +420,16 @@ impl PullRequestDiffView {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(highlight_range) = highlight_range {
|
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 {
|
let content = match search_result.cursor.side {
|
||||||
| util::diff::DiffSide::Old => diff_view_state.old_side_highlights_mut(),
|
| util::diff::DiffSide::Old => diff_view_state.old_side_highlights_mut(),
|
||||||
| util::diff::DiffSide::New => diff_view_state.new_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();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user