on master help sign in
Properly fix `last_line` view calculation.

Turned out to be simpler than I thought. Didn't even need to change the other use-sites.

commit079d4ed86df30c78ca00fd4b86f906c3ea9df7db authorNathan Vegdahl <cessen@cessen.com> dateMon 19 Jul 2021, 08:39 (5 years ago) parent1a9ae72
2 files changed+4−12
helix-term/src/ui/editor.rs+1−10 helix-view/src/view.rs+3−2
helix-term/src/ui/editor.rs+1−10
@@ -330,16 +330,7 @@ impl EditorView {
330330 // document or not. We only draw it if it's not an empty line.
331331 let draw_last = text.line_to_byte(last_line) < text.len_bytes();
332332
333− // This is a little confuding: We can't use the `last_line` variable for
334− // our iteration below, because there's a mismatch between the
335− // inclusive/exclusiveness of the screen-based last line and the
336− // text-based last line. So we compute what we actually need specially here.
337− let last_line_number = std::cmp::min(
338− view.first_line + view.area.height.saturating_sub(1) as usize,
339− doc.text().len_lines(),
340− );
341−
342− for (i, line) in (view.first_line..last_line_number).enumerate() {
333+ for (i, line) in (view.first_line..(last_line + 1)).enumerate() {
343334 use helix_core::diagnostic::Severity;
344335 if let Some(diagnostic) = doc.diagnostics().iter().find(|d| d.line == line) {
345336 surface.set_stringn(
helix-view/src/view.rs+3−2
@@ -119,8 +119,9 @@ impl View {
119119 pub fn last_line(&self, doc: &Document) -> usize {
120120 let height = self.area.height.saturating_sub(1); // - 1 for statusline
121121 std::cmp::min(
122− self.first_line + height as usize,
123− doc.text().len_lines() - 1,
122+ // Saturating subs to make it inclusive zero indexing.
123+ (self.first_line + height as usize).saturating_sub(1),
124+ doc.text().len_lines().saturating_sub(1),
124125 )
125126 }
126127