mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-07 12:05:34 +00:00
perf: skip ratatui span when match at end of string (#91)
perf: skip ratatui span when match end of string - for the entry name, we don't create an empty ratatui span when the match is right at the end of the entry name - same for the preview, we don't create a ratatui span anymore when the match is at the end of the preview
This commit is contained in:
parent
20cf83b720
commit
b7ddb00c4e
@ -96,22 +96,29 @@ where
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|(s, e)| (*s as usize, *e as usize))
|
.map(|(s, e)| (*s as usize, *e as usize))
|
||||||
{
|
{
|
||||||
|
// from the end of the last match to the start of the current one
|
||||||
spans.push(Span::styled(
|
spans.push(Span::styled(
|
||||||
slice_at_char_boundaries(&entry_name, last_match_end, start)
|
slice_at_char_boundaries(&entry_name, last_match_end, start)
|
||||||
.to_string(),
|
.to_string(),
|
||||||
Style::default().fg(results_list_colors.result_name_fg),
|
Style::default().fg(results_list_colors.result_name_fg),
|
||||||
));
|
));
|
||||||
|
// the current match
|
||||||
spans.push(Span::styled(
|
spans.push(Span::styled(
|
||||||
slice_at_char_boundaries(&entry_name, start, end).to_string(),
|
slice_at_char_boundaries(&entry_name, start, end).to_string(),
|
||||||
Style::default().fg(Color::Red),
|
Style::default().fg(Color::Red),
|
||||||
));
|
));
|
||||||
last_match_end = end;
|
last_match_end = end;
|
||||||
}
|
}
|
||||||
|
// we need to push a span for the remainder of the entry name
|
||||||
|
// but only if there's something left
|
||||||
|
let next_boundary = next_char_boundary(&entry_name, last_match_end);
|
||||||
|
if next_boundary < entry_name.len() {
|
||||||
|
let remainder = entry_name[next_boundary..].to_string();
|
||||||
spans.push(Span::styled(
|
spans.push(Span::styled(
|
||||||
entry_name[next_char_boundary(&entry_name, last_match_end)..]
|
remainder,
|
||||||
.to_string(),
|
|
||||||
Style::default().fg(results_list_colors.result_name_fg),
|
Style::default().fg(results_list_colors.result_name_fg),
|
||||||
));
|
));
|
||||||
|
}
|
||||||
// optional line number
|
// optional line number
|
||||||
if let Some(line_number) = entry.line_number {
|
if let Some(line_number) = entry.line_number {
|
||||||
spans.push(Span::styled(
|
spans.push(Span::styled(
|
||||||
@ -144,12 +151,14 @@ where
|
|||||||
));
|
));
|
||||||
last_match_end = end;
|
last_match_end = end;
|
||||||
}
|
}
|
||||||
|
let next_boundary = next_char_boundary(&preview, last_match_end);
|
||||||
|
if next_boundary < preview.len() {
|
||||||
spans.push(Span::styled(
|
spans.push(Span::styled(
|
||||||
preview[next_char_boundary(&preview, last_match_end)..]
|
preview[next_boundary..].to_string(),
|
||||||
.to_string(),
|
|
||||||
Style::default().fg(results_list_colors.result_preview_fg),
|
Style::default().fg(results_list_colors.result_preview_fg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Line::from(spans)
|
Line::from(spans)
|
||||||
}))
|
}))
|
||||||
.direction(list_direction)
|
.direction(list_direction)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user