fix: search result advancing highlight
This commit is contained in:
@@ -25,7 +25,6 @@ pub(crate) struct PullRequestDiffView {
|
|||||||
diff_view_state_in_search_mode: Option<DiffViewState>,
|
diff_view_state_in_search_mode: Option<DiffViewState>,
|
||||||
diff_view_content: Option<DiffViewContent>,
|
diff_view_content: Option<DiffViewContent>,
|
||||||
diff_search_result: Option<DiffSearchResult>,
|
diff_search_result: Option<DiffSearchResult>,
|
||||||
diff_search_result_cursor: Option<DiffSearchResultCursor>,
|
|
||||||
|
|
||||||
current_file_path: Option<Arc<str>>,
|
current_file_path: Option<Arc<str>>,
|
||||||
|
|
||||||
@@ -36,6 +35,7 @@ pub(crate) struct PullRequestDiffView {
|
|||||||
struct DiffSearchHit {
|
struct DiffSearchHit {
|
||||||
diff_line_i: DiffLineIndex,
|
diff_line_i: DiffLineIndex,
|
||||||
src_byte_range: std::ops::Range<usize>,
|
src_byte_range: std::ops::Range<usize>,
|
||||||
|
highlight_range: util::syntax_highlight::HighlightedRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DiffSearchResult {
|
struct DiffSearchResult {
|
||||||
@@ -62,7 +62,6 @@ impl PullRequestDiffView {
|
|||||||
diff_view_content: None,
|
diff_view_content: None,
|
||||||
diff_view_state_in_search_mode: None,
|
diff_view_state_in_search_mode: None,
|
||||||
diff_search_result: None,
|
diff_search_result: None,
|
||||||
diff_search_result_cursor: None,
|
|
||||||
current_file_path: None,
|
current_file_path: None,
|
||||||
|
|
||||||
focus_handle: cx.focus_handle(),
|
focus_handle: cx.focus_handle(),
|
||||||
@@ -239,7 +238,8 @@ impl PullRequestDiffView {
|
|||||||
.diff_line_index_for_line(util::diff::DiffSide::Old, line_idx);
|
.diff_line_index_for_line(util::diff::DiffSide::Old, line_idx);
|
||||||
Some(DiffSearchHit {
|
Some(DiffSearchHit {
|
||||||
diff_line_i,
|
diff_line_i,
|
||||||
src_byte_range: range,
|
src_byte_range: range.clone(),
|
||||||
|
highlight_range: (range, symbol_highlight_style(theme)),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
@@ -255,23 +255,18 @@ impl PullRequestDiffView {
|
|||||||
.diff_line_index_for_line(util::diff::DiffSide::New, line_idx);
|
.diff_line_index_for_line(util::diff::DiffSide::New, line_idx);
|
||||||
Some(DiffSearchHit {
|
Some(DiffSearchHit {
|
||||||
diff_line_i,
|
diff_line_i,
|
||||||
src_byte_range: range,
|
src_byte_range: range.clone(),
|
||||||
|
highlight_range: (range, symbol_highlight_style(theme)),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let old_side_highlights =
|
let old_side_highlights = old_search_result
|
||||||
old_search_result
|
.iter()
|
||||||
.iter()
|
.map(|hit| -> &util::syntax_highlight::HighlightedRange { &hit.highlight_range });
|
||||||
.map(|hit| -> util::syntax_highlight::HighlightedRange {
|
let new_side_highlights = new_search_result
|
||||||
(hit.src_byte_range.clone(), symbol_highlight_style(theme))
|
.iter()
|
||||||
});
|
.map(|hit| -> &util::syntax_highlight::HighlightedRange { &hit.highlight_range });
|
||||||
let new_side_highlights =
|
|
||||||
new_search_result
|
|
||||||
.iter()
|
|
||||||
.map(|hit| -> util::syntax_highlight::HighlightedRange {
|
|
||||||
(hit.src_byte_range.clone(), symbol_highlight_style(theme))
|
|
||||||
});
|
|
||||||
|
|
||||||
if let Some(h) = self
|
if let Some(h) = self
|
||||||
.diff_view_state
|
.diff_view_state
|
||||||
@@ -323,18 +318,38 @@ impl PullRequestDiffView {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let (current_side, other_side) = match search_result.cursor.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 theme = app::current_theme(cx);
|
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)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
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) {
|
||||||
| Some(DiffSearchHit {
|
| Some(DiffSearchHit {
|
||||||
diff_line_i,
|
diff_line_i,
|
||||||
src_byte_range,
|
src_byte_range,
|
||||||
|
..
|
||||||
}) if *diff_line_i == current_search_hit.diff_line_i => {
|
}) if *diff_line_i == current_search_hit.diff_line_i => {
|
||||||
// go to next search result on same side & same line
|
// go to next search result on same side & same line
|
||||||
search_result.cursor.index += 1;
|
search_result.cursor.index += 1;
|
||||||
@@ -357,6 +372,7 @@ impl PullRequestDiffView {
|
|||||||
while let Some(DiffSearchHit {
|
while let Some(DiffSearchHit {
|
||||||
diff_line_i,
|
diff_line_i,
|
||||||
src_byte_range,
|
src_byte_range,
|
||||||
|
..
|
||||||
}) = &other_side.get(i)
|
}) = &other_side.get(i)
|
||||||
{
|
{
|
||||||
if *diff_line_i == current_search_hit.diff_line_i
|
if *diff_line_i == current_search_hit.diff_line_i
|
||||||
|
|||||||
@@ -122,9 +122,9 @@ impl HighlightedContent {
|
|||||||
&self.0[line].line_range
|
&self.0[line].line_range
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn extended_with_highlights(
|
pub(crate) fn extended_with_highlights<'a>(
|
||||||
mut self,
|
mut self,
|
||||||
highlights: impl Iterator<Item = HighlightedRange>,
|
highlights: impl Iterator<Item = &'a HighlightedRange>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let total_line_count = self.0.len();
|
let total_line_count = self.0.len();
|
||||||
let mut current_line: usize = 0;
|
let mut current_line: usize = 0;
|
||||||
@@ -191,8 +191,6 @@ impl HighlightedContent {
|
|||||||
pub(crate) fn replace_highlight_range(&mut self, highlighted_range: &HighlightedRange) {
|
pub(crate) fn replace_highlight_range(&mut self, highlighted_range: &HighlightedRange) {
|
||||||
let (range, _) = &highlighted_range;
|
let (range, _) = &highlighted_range;
|
||||||
|
|
||||||
println!("finding range to replace {:?}", range);
|
|
||||||
|
|
||||||
let line = self
|
let line = self
|
||||||
.line_index_of_range(range)
|
.line_index_of_range(range)
|
||||||
.map(|line_i| &mut self.0[line_i]);
|
.map(|line_i| &mut self.0[line_i]);
|
||||||
|
|||||||
Reference in New Issue
Block a user