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:
Antonio Scandurra 2021-11-17 19:30:40 +01:00
parent d9283efbe6
commit 198f6694b7
2 changed files with 7 additions and 7 deletions

View file

@ -702,7 +702,7 @@ impl Snapshot {
prev_tab_row = tab_point.row();
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() {
@ -782,7 +782,7 @@ impl<'a> Iterator for Chunks<'a> {
}
impl<'a> Iterator for BufferRows<'a> {
type Item = (u32, bool);
type Item = Option<u32>;
fn next(&mut self) -> Option<Self::Item> {
if self.output_row > self.max_output_row {
@ -802,7 +802,7 @@ impl<'a> Iterator for BufferRows<'a> {
self.soft_wrapped = true;
}
Some((buffer_row, soft_wrapped))
Some(if soft_wrapped { None } else { Some(buffer_row) })
}
}

View file

@ -411,7 +411,7 @@ impl EditorElement {
let style = &self.settings.style;
let mut layouts = Vec::with_capacity(rows.len());
let mut line_number = String::new();
for (ix, (buffer_row, soft_wrapped)) in snapshot
for (ix, buffer_row) in snapshot
.buffer_rows(rows.start)
.take((rows.end - rows.start) as usize)
.enumerate()
@ -422,9 +422,7 @@ impl EditorElement {
} else {
style.line_number
};
if soft_wrapped {
layouts.push(None);
} else {
if let Some(buffer_row) = buffer_row {
line_number.clear();
write!(&mut line_number, "{}", buffer_row + 1).unwrap();
layouts.push(Some(cx.text_layout_cache.layout_str(
@ -439,6 +437,8 @@ impl EditorElement {
},
)],
)));
} else {
layouts.push(None);
}
}