Skip to content

Commit 7effac9

Browse files
committed
fix: only render inline blame once per line at most
Renders inline blame for the last visual line
1 parent be5fbff commit 7effac9

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

helix-term/src/ui/document.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ pub struct LinePos {
8181
pub doc_line: usize,
8282
/// Vertical offset from the top of the inner view area
8383
pub visual_line: u16,
84+
/// The given visual line is the last visual line of the document line
85+
pub is_last_visual_line: bool,
8486
}
8587

8688
#[allow(clippy::too_many_arguments)]
@@ -154,6 +156,7 @@ pub fn render_text(
154156
first_visual_line: false,
155157
doc_line: usize::MAX,
156158
visual_line: u16::MAX,
159+
is_last_visual_line: true,
157160
};
158161
let mut last_line_end = 0;
159162
let mut is_in_indent_area = true;
@@ -188,6 +191,10 @@ pub fn render_text(
188191

189192
// apply decorations before rendering a new line
190193
if grapheme.visual_pos.row as u16 != last_line_pos.visual_line {
194+
if last_line_pos.doc_line == grapheme.line_idx {
195+
last_line_pos.is_last_visual_line = false;
196+
}
197+
191198
// we initiate doc_line with usize::MAX because no file
192199
// can reach that size (memory allocations are limited to isize::MAX)
193200
// initially there is no "previous" line (so doc_line is set to usize::MAX)
@@ -202,6 +209,7 @@ pub fn render_text(
202209
first_visual_line: grapheme.line_idx != last_line_pos.doc_line,
203210
doc_line: grapheme.line_idx,
204211
visual_line: grapheme.visual_pos.row as u16,
212+
is_last_visual_line: true,
205213
};
206214
decorations.decorate_line(renderer, last_line_pos);
207215
}

helix-term/src/ui/text_decorations/blame.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ impl Decoration for InlineBlame {
3131
pos: LinePos,
3232
virt_off: Position,
3333
) -> Position {
34+
// Only render inline blame on the last visual line
35+
// This prevents it being rendered multiple times per line, if the
36+
// line is wrapping.
37+
//
38+
// We want to render it on the last visual line because unless the user
39+
// has `soft-wrap.wrap-at-text-width` enabled, for a document line that wraps
40+
// there will only be space to render inline blame at the last doc line
41+
if !pos.is_last_visual_line {
42+
return Position::new(0, 0);
43+
}
44+
3445
let blame = match &self.lines {
3546
LineBlame::OneLine((line, blame)) => {
3647
if line == &pos.doc_line {

0 commit comments

Comments
 (0)