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)]
|
#[derive(Default, Debug)]
|
||||||
struct HighlightedTextBuilder {
|
struct HighlightedTextBuilder {
|
||||||
pub text: String,
|
pub text: String,
|
||||||
pub highlights: Vec<(Range<usize>, HighlightStyle)>,
|
highlights: Vec<(Range<usize>, HighlightStyle)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HighlightedText {
|
impl HighlightedText {
|
||||||
@@ -624,10 +624,11 @@ impl HighlightedText {
|
|||||||
let preview_highlights = self
|
let preview_highlights = self
|
||||||
.highlights
|
.highlights
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
.skip_while(|(range, _)| range.end <= preview_start_ix)
|
||||||
.take_while(|(range, _)| range.start < newline_ix)
|
.take_while(|(range, _)| range.start < newline_ix)
|
||||||
.filter_map(|(mut range, highlight)| {
|
.filter_map(|(mut range, highlight)| {
|
||||||
range.start = range.start.saturating_sub(preview_start_ix);
|
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() {
|
if range.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user