Skip to content

Commit fb0d809

Browse files
committed
Fix interaction between navigate and (hunk-header-style without "line-number")
Prior to this commit we were emitting a spurious colon when hunk-header-style was set to a value such as "syntax" (i.e. not including "line-number") and navigate was enabled. Fixes #672
1 parent 7974d95 commit fb0d809

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/handlers/hunk_header.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::config::Config;
2929
use crate::delta::{self, State, StateMachine};
3030
use crate::features;
3131
use crate::paint::Painter;
32-
use crate::style::{DecorationStyle, Style};
32+
use crate::style::DecorationStyle;
3333

3434
impl<'a> StateMachine<'a> {
3535
#[inline]
@@ -170,12 +170,7 @@ fn write_hunk_header(
170170
let file_with_line_number = get_painted_file_with_line_number(line_numbers, plus_file, config);
171171

172172
if !line.is_empty() || !file_with_line_number.is_empty() {
173-
write_to_output_buffer(
174-
&file_with_line_number,
175-
line,
176-
config.hunk_header_style,
177-
painter,
178-
);
173+
write_to_output_buffer(&file_with_line_number, line, painter, config);
179174
draw_fn(
180175
painter.writer,
181176
&painter.output_buffer,
@@ -196,11 +191,6 @@ fn get_painted_file_with_line_number(
196191
config: &Config,
197192
) -> String {
198193
let mut file_with_line_number = Vec::new();
199-
let hunk_label;
200-
if config.navigate {
201-
hunk_label = format!("{} ", config.hunk_label);
202-
file_with_line_number.push(config.hunk_header_file_style.paint(&hunk_label));
203-
}
204194
let plus_line_number = line_numbers[line_numbers.len() - 1].0;
205195
if config.hunk_header_style_include_file_path {
206196
file_with_line_number.push(config.hunk_header_file_style.paint(plus_file))
@@ -235,16 +225,23 @@ fn get_painted_file_with_line_number(
235225
fn write_to_output_buffer(
236226
file_with_line_number: &str,
237227
line: String,
238-
style: Style,
239228
painter: &mut Painter,
229+
config: &Config,
240230
) {
231+
if config.navigate {
232+
let _ = write!(
233+
&mut painter.output_buffer,
234+
"{} ",
235+
config.hunk_header_file_style.paint(&config.hunk_label)
236+
);
237+
}
241238
if !file_with_line_number.is_empty() {
242239
let _ = write!(&mut painter.output_buffer, "{}: ", file_with_line_number);
243240
}
244241
if !line.is_empty() {
245242
painter.syntax_highlight_and_paint_line(
246243
&line,
247-
style,
244+
config.hunk_header_style,
248245
delta::State::HunkHeader("".to_owned(), "".to_owned()),
249246
false,
250247
);

0 commit comments

Comments
 (0)