editor: Use proper rows for fold indicators in the gutter (#11741)
Follow-up to #11656 Release Notes: - N/A --------- Co-authored-by: Kirill <kirill@zed.dev>
This commit is contained in:
parent
1afcd12747
commit
c90263d59b
2 changed files with 17 additions and 29 deletions
|
@ -70,17 +70,6 @@ pub trait ToDisplayPoint {
|
||||||
type TextHighlights = TreeMap<Option<TypeId>, Arc<(HighlightStyle, Vec<Range<Anchor>>)>>;
|
type TextHighlights = TreeMap<Option<TypeId>, Arc<(HighlightStyle, Vec<Range<Anchor>>)>>;
|
||||||
type InlayHighlights = TreeMap<TypeId, TreeMap<InlayId, (HighlightStyle, InlayHighlight)>>;
|
type InlayHighlights = TreeMap<TypeId, TreeMap<InlayId, (HighlightStyle, InlayHighlight)>>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct DisplayBufferRows<'a>(BlockBufferRows<'a>);
|
|
||||||
|
|
||||||
impl<'a> Iterator for DisplayBufferRows<'a> {
|
|
||||||
type Item = Option<DisplayRow>;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
self.0.next().map(|row| row.map(|r| DisplayRow(r.0)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Decides how text in a [`MultiBuffer`] should be displayed in a buffer, handling inlay hints,
|
/// Decides how text in a [`MultiBuffer`] should be displayed in a buffer, handling inlay hints,
|
||||||
/// folding, hard tabs, soft wrapping, custom blocks (like diagnostics), and highlighting.
|
/// folding, hard tabs, soft wrapping, custom blocks (like diagnostics), and highlighting.
|
||||||
///
|
///
|
||||||
|
@ -398,8 +387,13 @@ impl DisplaySnapshot {
|
||||||
self.buffer_snapshot.len() == 0
|
self.buffer_snapshot.len() == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn display_rows(&self, start_row: DisplayRow) -> DisplayBufferRows {
|
pub fn buffer_rows(
|
||||||
DisplayBufferRows(self.block_snapshot.buffer_rows(BlockRow(start_row.0)))
|
&self,
|
||||||
|
start_row: DisplayRow,
|
||||||
|
) -> impl Iterator<Item = Option<MultiBufferRow>> + '_ {
|
||||||
|
self.block_snapshot
|
||||||
|
.buffer_rows(BlockRow(start_row.0))
|
||||||
|
.map(|row| row.map(|row| MultiBufferRow(row.0)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn max_buffer_row(&self) -> MultiBufferRow {
|
pub fn max_buffer_row(&self) -> MultiBufferRow {
|
||||||
|
|
|
@ -1516,7 +1516,7 @@ impl EditorElement {
|
||||||
let end = rows.end.max(relative_to);
|
let end = rows.end.max(relative_to);
|
||||||
|
|
||||||
let buffer_rows = snapshot
|
let buffer_rows = snapshot
|
||||||
.display_rows(start)
|
.buffer_rows(start)
|
||||||
.take(1 + end.minus(start) as usize)
|
.take(1 + end.minus(start) as usize)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
@ -1554,7 +1554,7 @@ impl EditorElement {
|
||||||
fn layout_line_numbers(
|
fn layout_line_numbers(
|
||||||
&self,
|
&self,
|
||||||
rows: Range<DisplayRow>,
|
rows: Range<DisplayRow>,
|
||||||
buffer_rows: impl Iterator<Item = Option<DisplayRow>>,
|
buffer_rows: impl Iterator<Item = Option<MultiBufferRow>>,
|
||||||
active_rows: &BTreeMap<DisplayRow, bool>,
|
active_rows: &BTreeMap<DisplayRow, bool>,
|
||||||
newest_selection_head: Option<DisplayPoint>,
|
newest_selection_head: Option<DisplayPoint>,
|
||||||
snapshot: &EditorSnapshot,
|
snapshot: &EditorSnapshot,
|
||||||
|
@ -1602,10 +1602,10 @@ impl EditorElement {
|
||||||
} else {
|
} else {
|
||||||
(false, cx.theme().colors().editor_line_number)
|
(false, cx.theme().colors().editor_line_number)
|
||||||
};
|
};
|
||||||
if let Some(display_row) = row {
|
if let Some(multibuffer_row) = row {
|
||||||
if include_line_numbers {
|
if include_line_numbers {
|
||||||
line_number.clear();
|
line_number.clear();
|
||||||
let default_number = display_row.0 + 1;
|
let default_number = multibuffer_row.0 + 1;
|
||||||
let number = relative_rows
|
let number = relative_rows
|
||||||
.get(&DisplayRow(ix as u32 + rows.start.0))
|
.get(&DisplayRow(ix as u32 + rows.start.0))
|
||||||
.unwrap_or(&default_number);
|
.unwrap_or(&default_number);
|
||||||
|
@ -1628,9 +1628,6 @@ impl EditorElement {
|
||||||
fold_statuses.push(
|
fold_statuses.push(
|
||||||
is_singleton
|
is_singleton
|
||||||
.then(|| {
|
.then(|| {
|
||||||
let multibuffer_point =
|
|
||||||
DisplayPoint::new(display_row, 0).to_point(snapshot);
|
|
||||||
let multibuffer_row = MultiBufferRow(multibuffer_point.row);
|
|
||||||
snapshot
|
snapshot
|
||||||
.fold_for_line(multibuffer_row)
|
.fold_for_line(multibuffer_row)
|
||||||
.map(|fold_status| (fold_status, multibuffer_row, active))
|
.map(|fold_status| (fold_status, multibuffer_row, active))
|
||||||
|
@ -3861,8 +3858,9 @@ impl Element for EditorElement {
|
||||||
let end_row = DisplayRow(end_row);
|
let end_row = DisplayRow(end_row);
|
||||||
|
|
||||||
let buffer_rows = snapshot
|
let buffer_rows = snapshot
|
||||||
.display_rows(start_row)
|
.buffer_rows(start_row)
|
||||||
.take((start_row..end_row).len());
|
.take((start_row..end_row).len())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let start_anchor = if start_row == Default::default() {
|
let start_anchor = if start_row == Default::default() {
|
||||||
Anchor::min()
|
Anchor::min()
|
||||||
|
@ -3905,7 +3903,7 @@ impl Element for EditorElement {
|
||||||
|
|
||||||
let (line_numbers, fold_statuses) = self.layout_line_numbers(
|
let (line_numbers, fold_statuses) = self.layout_line_numbers(
|
||||||
start_row..end_row,
|
start_row..end_row,
|
||||||
buffer_rows.clone(),
|
buffer_rows.clone().into_iter(),
|
||||||
&active_rows,
|
&active_rows,
|
||||||
newest_selection_head,
|
newest_selection_head,
|
||||||
&snapshot,
|
&snapshot,
|
||||||
|
@ -3975,11 +3973,7 @@ impl Element for EditorElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
let blamed_display_rows = self.layout_blame_entries(
|
let blamed_display_rows = self.layout_blame_entries(
|
||||||
buffer_rows.map(|display_row| {
|
buffer_rows.into_iter(),
|
||||||
display_row.map(|row| {
|
|
||||||
MultiBufferRow(DisplayPoint::new(row, 0).to_point(&snapshot).row)
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
em_width,
|
em_width,
|
||||||
scroll_position,
|
scroll_position,
|
||||||
line_height,
|
line_height,
|
||||||
|
@ -4884,7 +4878,7 @@ mod tests {
|
||||||
element
|
element
|
||||||
.layout_line_numbers(
|
.layout_line_numbers(
|
||||||
DisplayRow(0)..DisplayRow(6),
|
DisplayRow(0)..DisplayRow(6),
|
||||||
(0..6).map(DisplayRow).map(Some),
|
(0..6).map(MultiBufferRow).map(Some),
|
||||||
&Default::default(),
|
&Default::default(),
|
||||||
Some(DisplayPoint::new(DisplayRow(0), 0)),
|
Some(DisplayPoint::new(DisplayRow(0), 0)),
|
||||||
&snapshot,
|
&snapshot,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue