Skip to content

Commit

Permalink
Find correct last_visible_line in Editor::highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Sep 18, 2023
1 parent 8f8528a commit d1440ce
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions graphics/src/text/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,27 @@ impl editor::Editor for Editor {
let internal = self.internal();
let buffer = internal.editor.buffer();

let scroll = buffer.scroll();
let visible_lines = buffer.visible_lines();
let last_visible_line = ((scroll + visible_lines) as usize)
.min(buffer.lines.len())
.saturating_sub(1);
let mut window = buffer.scroll() + buffer.visible_lines();

let last_visible_line = buffer
.lines
.iter()
.enumerate()
.find_map(|(i, line)| {
let visible_lines = line
.layout_opt()
.as_ref()
.expect("Line layout should be cached")
.len() as i32;

if window > visible_lines {
window -= visible_lines;
None
} else {
Some(i)
}
})
.unwrap_or(buffer.lines.len());

let current_line = highlighter.current_line();

Expand Down

0 comments on commit d1440ce

Please sign in to comment.