language: Fix HighlightedText::first_line_preview creating incorrect highlight ranges (#39705)
Fixes ZED-1XW Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
@@ -581,7 +581,7 @@ pub struct HighlightedText {
|
||||
#[derive(Default, Debug)]
|
||||
struct HighlightedTextBuilder {
|
||||
pub text: String,
|
||||
pub highlights: Vec<(Range<usize>, HighlightStyle)>,
|
||||
highlights: Vec<(Range<usize>, HighlightStyle)>,
|
||||
}
|
||||
|
||||
impl HighlightedText {
|
||||
@@ -624,10 +624,11 @@ impl HighlightedText {
|
||||
let preview_highlights = self
|
||||
.highlights
|
||||
.into_iter()
|
||||
.skip_while(|(range, _)| range.end <= preview_start_ix)
|
||||
.take_while(|(range, _)| range.start < newline_ix)
|
||||
.filter_map(|(mut range, highlight)| {
|
||||
range.start = range.start.saturating_sub(preview_start_ix);
|
||||
range.end = range.end.saturating_sub(preview_start_ix).min(newline_ix);
|
||||
range.end = range.end.min(newline_ix).saturating_sub(preview_start_ix);
|
||||
if range.is_empty() {
|
||||
None
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user