Skip to content

Commit 2156aa8

Browse files
committed
refactor: Move full_line lookup into the branches that use it
1 parent da627fe commit 2156aa8

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

src/renderer/render.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,34 +1723,26 @@ fn emit_suggestion_default(
17231723
// logic to show the whole prior snippet, but the current output is not
17241724
// too bad to begin with, so we side-step that issue here.
17251725
for (i, line) in snippet.lines().enumerate() {
1726-
let full_line = if i == 0 {
1727-
// `snippet` starts at the first character that must be edited,
1728-
// which often does not contain the indent of the line. Retrieve
1729-
// the full line in order to avoid missing leading tabs.
1730-
sm.get_line(span_start.line).unwrap_or_default()
1731-
} else {
1732-
line
1733-
};
1734-
1735-
let line = normalize_whitespace(line);
1726+
let norm_line = normalize_whitespace(line);
17361727
// Going lower than buffer_offset (+ 1) would mean
17371728
// overwriting existing content in the buffer
17381729
let min_row = buffer_offset + usize::from(!matches_previous_suggestion);
17391730
let row = (row_num - 2 - (offset - i - 1)).max(min_row);
17401731
let (start, end) = if i == 0 {
17411732
// On the first line, we highlight between the start of the part
17421733
// span, and the end of that line.
1734+
let full_line = sm.get_line(span_start.line).unwrap_or_default();
17431735
let extra_width = extra_width_from_tabs(full_line, span_start.char);
17441736
let start = span_start.char + extra_width;
1745-
(start, start + line.chars().count())
1737+
(start, start + norm_line.chars().count())
17461738
} else if i == newlines - 1 {
17471739
// On the last line, we highlight between the start of the line, and
17481740
// the column of the part span end.
1749-
let extra_width = extra_width_from_tabs(full_line, span_start.char);
1741+
let extra_width = extra_width_from_tabs(line, span_start.char);
17501742
(0, span_end.char + extra_width)
17511743
} else {
17521744
// On all others, we highlight the whole line.
1753-
(0, line.chars().count())
1745+
(0, norm_line.chars().count())
17541746
};
17551747
buffer.set_style_range(
17561748
row,

0 commit comments

Comments
 (0)