mirror of https://github.com/helix-editor/helix
perf: do not render inline blame on invisible lines
parent
ac0e677fae
commit
d34074af1b
|
@ -219,15 +219,29 @@ impl EditorView {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else if config.inline_blame.behaviour == InlineBlameBehaviour::AllLines {
|
} else if config.inline_blame.behaviour == InlineBlameBehaviour::AllLines {
|
||||||
let blame_for_all_lines = (0..doc.text().len_lines())
|
let text = doc.text();
|
||||||
|
let len_lines = text.len_lines();
|
||||||
|
let view_height = view.inner_height();
|
||||||
|
let first_visible_line =
|
||||||
|
text.char_to_line(doc.view_offset(view.id).anchor.min(text.len_chars()));
|
||||||
|
let first_line = first_visible_line.saturating_sub(view_height);
|
||||||
|
let last_line = first_visible_line
|
||||||
|
.saturating_add(view_height.saturating_mul(2))
|
||||||
|
.min(len_lines);
|
||||||
|
|
||||||
|
// Compute ~3 times the current view height of inline blame, that way some scrolling
|
||||||
|
// will not show half the view with inline blame and half without while still being faster
|
||||||
|
// than rendering inline blame for the full file.
|
||||||
|
let blame_for_all_lines = (first_line..last_line)
|
||||||
.filter_map(|line_idx| {
|
.filter_map(|line_idx| {
|
||||||
(doc.text().line(line_idx) != doc.line_ending.as_str())
|
// do not render inline blame for empty lines to reduce visual noise
|
||||||
.then(|| {
|
if text.line(line_idx) != doc.line_ending.as_str() {
|
||||||
doc.line_blame(line_idx as u32, &config.inline_blame.format)
|
doc.line_blame(line_idx as u32, &config.inline_blame.format)
|
||||||
.ok()
|
.ok()
|
||||||
.map(|blame| (line_idx, blame))
|
.map(|blame| (line_idx, blame))
|
||||||
})
|
} else {
|
||||||
.flatten()
|
None
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
decorations.add_decoration(InlineBlame::new(theme, blame_for_all_lines));
|
decorations.add_decoration(InlineBlame::new(theme, blame_for_all_lines));
|
||||||
|
|
Loading…
Reference in New Issue