Use options to represent soft-wrapped buffer rows
Co-Authored-By: Nathan Sobo <nathan@zed.dev> Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
parent
d9283efbe6
commit
198f6694b7
2 changed files with 7 additions and 7 deletions
|
@ -702,7 +702,7 @@ impl Snapshot {
|
||||||
prev_tab_row = tab_point.row();
|
prev_tab_row = tab_point.row();
|
||||||
soft_wrapped = false;
|
soft_wrapped = false;
|
||||||
}
|
}
|
||||||
expected_buffer_rows.push((buffer_row, soft_wrapped));
|
expected_buffer_rows.push(if soft_wrapped { None } else { Some(buffer_row) });
|
||||||
}
|
}
|
||||||
|
|
||||||
for start_display_row in 0..expected_buffer_rows.len() {
|
for start_display_row in 0..expected_buffer_rows.len() {
|
||||||
|
@ -782,7 +782,7 @@ impl<'a> Iterator for Chunks<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for BufferRows<'a> {
|
impl<'a> Iterator for BufferRows<'a> {
|
||||||
type Item = (u32, bool);
|
type Item = Option<u32>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
if self.output_row > self.max_output_row {
|
if self.output_row > self.max_output_row {
|
||||||
|
@ -802,7 +802,7 @@ impl<'a> Iterator for BufferRows<'a> {
|
||||||
self.soft_wrapped = true;
|
self.soft_wrapped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Some((buffer_row, soft_wrapped))
|
Some(if soft_wrapped { None } else { Some(buffer_row) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -411,7 +411,7 @@ impl EditorElement {
|
||||||
let style = &self.settings.style;
|
let style = &self.settings.style;
|
||||||
let mut layouts = Vec::with_capacity(rows.len());
|
let mut layouts = Vec::with_capacity(rows.len());
|
||||||
let mut line_number = String::new();
|
let mut line_number = String::new();
|
||||||
for (ix, (buffer_row, soft_wrapped)) in snapshot
|
for (ix, buffer_row) in snapshot
|
||||||
.buffer_rows(rows.start)
|
.buffer_rows(rows.start)
|
||||||
.take((rows.end - rows.start) as usize)
|
.take((rows.end - rows.start) as usize)
|
||||||
.enumerate()
|
.enumerate()
|
||||||
|
@ -422,9 +422,7 @@ impl EditorElement {
|
||||||
} else {
|
} else {
|
||||||
style.line_number
|
style.line_number
|
||||||
};
|
};
|
||||||
if soft_wrapped {
|
if let Some(buffer_row) = buffer_row {
|
||||||
layouts.push(None);
|
|
||||||
} else {
|
|
||||||
line_number.clear();
|
line_number.clear();
|
||||||
write!(&mut line_number, "{}", buffer_row + 1).unwrap();
|
write!(&mut line_number, "{}", buffer_row + 1).unwrap();
|
||||||
layouts.push(Some(cx.text_layout_cache.layout_str(
|
layouts.push(Some(cx.text_layout_cache.layout_str(
|
||||||
|
@ -439,6 +437,8 @@ impl EditorElement {
|
||||||
},
|
},
|
||||||
)],
|
)],
|
||||||
)));
|
)));
|
||||||
|
} else {
|
||||||
|
layouts.push(None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue