mirror of https://github.com/helix-editor/helix
refactor: `match` over `if`
parent
ab5663891c
commit
082ba4d741
|
@ -254,53 +254,57 @@ impl EditorView {
|
|||
decorations: &mut DecorationManager,
|
||||
theme: &Theme,
|
||||
) {
|
||||
if inline_blame.behaviour == InlineBlameBehaviour::CursorLine {
|
||||
let cursor_line_idx = doc.cursor_line(view.id);
|
||||
match inline_blame.behaviour {
|
||||
InlineBlameBehaviour::Hidden => (),
|
||||
InlineBlameBehaviour::CursorLine => {
|
||||
let cursor_line_idx = doc.cursor_line(view.id);
|
||||
|
||||
// do not render inline blame for empty lines to reduce visual noise
|
||||
if doc.text().line(cursor_line_idx) != doc.line_ending.as_str() {
|
||||
if let Ok(line_blame) = doc.line_blame(cursor_line_idx as u32, &inline_blame.format)
|
||||
{
|
||||
decorations.add_decoration(InlineBlame::new(
|
||||
theme,
|
||||
text_decorations::blame::LineBlame::OneLine((cursor_line_idx, line_blame)),
|
||||
));
|
||||
};
|
||||
}
|
||||
} else if inline_blame.behaviour == InlineBlameBehaviour::AllLines {
|
||||
let text = doc.text();
|
||||
let text_line_count = 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(text_line_count);
|
||||
|
||||
let mut blame_lines = vec![None; text_line_count];
|
||||
|
||||
// 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| {
|
||||
// do not render inline blame for empty lines to reduce visual noise
|
||||
if text.line(line_idx) != doc.line_ending.as_str() {
|
||||
doc.line_blame(line_idx as u32, &inline_blame.format)
|
||||
.ok()
|
||||
.map(|blame| (line_idx, blame))
|
||||
} else {
|
||||
None
|
||||
if doc.text().line(cursor_line_idx) != doc.line_ending.as_str() {
|
||||
if let Ok(line_blame) = doc.line_blame(cursor_line_idx as u32, &inline_blame.format)
|
||||
{
|
||||
decorations.add_decoration(InlineBlame::new(
|
||||
theme,
|
||||
text_decorations::blame::LineBlame::OneLine((cursor_line_idx, line_blame)),
|
||||
));
|
||||
};
|
||||
}
|
||||
});
|
||||
},
|
||||
InlineBlameBehaviour::AllLines => {
|
||||
let text = doc.text();
|
||||
let text_line_count = 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(text_line_count);
|
||||
|
||||
for (line_idx, blame) in blame_for_all_lines {
|
||||
blame_lines[line_idx] = Some(blame);
|
||||
}
|
||||
decorations.add_decoration(InlineBlame::new(
|
||||
theme,
|
||||
text_decorations::blame::LineBlame::ManyLines(blame_lines),
|
||||
));
|
||||
let mut blame_lines = vec![None; text_line_count];
|
||||
|
||||
// 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| {
|
||||
// do not render inline blame for empty lines to reduce visual noise
|
||||
if text.line(line_idx) != doc.line_ending.as_str() {
|
||||
doc.line_blame(line_idx as u32, &inline_blame.format)
|
||||
.ok()
|
||||
.map(|blame| (line_idx, blame))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
|
||||
for (line_idx, blame) in blame_for_all_lines {
|
||||
blame_lines[line_idx] = Some(blame);
|
||||
}
|
||||
decorations.add_decoration(InlineBlame::new(
|
||||
theme,
|
||||
text_decorations::blame::LineBlame::ManyLines(blame_lines),
|
||||
));
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue