Allow highlighting editor rows from multiple sources concurrently (#9153)
This commit is contained in:
parent
f4a86e6fea
commit
41dc5fc412
9 changed files with 590 additions and 45 deletions
|
@ -665,19 +665,53 @@ impl EditorElement {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(highlighted_rows) = &layout.highlighted_rows {
|
||||
let mut paint_highlight = |highlight_row_start: u32, highlight_row_end: u32, color| {
|
||||
let origin = point(
|
||||
bounds.origin.x,
|
||||
bounds.origin.y
|
||||
+ (layout.position_map.line_height * highlighted_rows.start as f32)
|
||||
+ (layout.position_map.line_height * highlight_row_start as f32)
|
||||
- scroll_top,
|
||||
);
|
||||
let size = size(
|
||||
bounds.size.width,
|
||||
layout.position_map.line_height * highlighted_rows.len() as f32,
|
||||
layout.position_map.line_height
|
||||
* (highlight_row_end + 1 - highlight_row_start) as f32,
|
||||
);
|
||||
let highlighted_line_bg = cx.theme().colors().editor_highlighted_line_background;
|
||||
cx.paint_quad(fill(Bounds { origin, size }, highlighted_line_bg));
|
||||
cx.paint_quad(fill(Bounds { origin, size }, color));
|
||||
};
|
||||
let mut last_row = None;
|
||||
let mut highlight_row_start = 0u32;
|
||||
let mut highlight_row_end = 0u32;
|
||||
for (&row, &color) in &layout.highlighted_rows {
|
||||
let paint = last_row.map_or(false, |(last_row, last_color)| {
|
||||
last_color != color || last_row + 1 < row
|
||||
});
|
||||
|
||||
if paint {
|
||||
let paint_range_is_unfinished = highlight_row_end == 0;
|
||||
if paint_range_is_unfinished {
|
||||
highlight_row_end = row;
|
||||
last_row = None;
|
||||
}
|
||||
paint_highlight(highlight_row_start, highlight_row_end, color);
|
||||
highlight_row_start = 0;
|
||||
highlight_row_end = 0;
|
||||
if !paint_range_is_unfinished {
|
||||
highlight_row_start = row;
|
||||
last_row = Some((row, color));
|
||||
}
|
||||
} else {
|
||||
if last_row.is_none() {
|
||||
highlight_row_start = row;
|
||||
} else {
|
||||
highlight_row_end = row;
|
||||
}
|
||||
last_row = Some((row, color));
|
||||
}
|
||||
}
|
||||
if let Some((row, hsla)) = last_row {
|
||||
highlight_row_end = row;
|
||||
paint_highlight(highlight_row_start, highlight_row_end, hsla);
|
||||
}
|
||||
|
||||
let scroll_left =
|
||||
|
@ -2064,7 +2098,7 @@ impl EditorElement {
|
|||
let mut active_rows = BTreeMap::new();
|
||||
let is_singleton = editor.is_singleton(cx);
|
||||
|
||||
let highlighted_rows = editor.highlighted_rows();
|
||||
let highlighted_rows = editor.highlighted_display_rows(cx);
|
||||
let highlighted_ranges = editor.background_highlights_in_range(
|
||||
start_anchor..end_anchor,
|
||||
&snapshot.display_snapshot,
|
||||
|
@ -3198,7 +3232,7 @@ pub struct LayoutState {
|
|||
visible_anchor_range: Range<Anchor>,
|
||||
visible_display_row_range: Range<u32>,
|
||||
active_rows: BTreeMap<u32, bool>,
|
||||
highlighted_rows: Option<Range<u32>>,
|
||||
highlighted_rows: BTreeMap<u32, Hsla>,
|
||||
line_numbers: Vec<Option<ShapedLine>>,
|
||||
display_hunks: Vec<DisplayDiffHunk>,
|
||||
blocks: Vec<BlockLayout>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue