diff options
Diffstat (limited to 'src/paint.rs')
-rw-r--r-- | src/paint.rs | 66 |
1 files changed, 59 insertions, 7 deletions
diff --git a/src/paint.rs b/src/paint.rs index 225e627d..902f4fe4 100644 --- a/src/paint.rs +++ b/src/paint.rs @@ -14,6 +14,7 @@ use crate::features::line_numbers; use crate::features::side_by_side; use crate::features::side_by_side::available_line_width; use crate::features::side_by_side::LeftRight; +use crate::features::side_by_side_wrap; use crate::paint::superimpose_style_sections::superimpose_style_sections; use crate::style::Style; @@ -110,6 +111,7 @@ impl<'a> Painter<'a> { // in effect in which case we replace it with the appropriate marker). // TODO: Things should, but do not, work if this leading space is omitted at this stage. // See comment in align::Alignment::new. + // Note that a wrapped line also has a leading character added to remain compatible. line.next(); format!(" {}\n", self.expand_tabs(line)) } else { @@ -179,8 +181,14 @@ impl<'a> Painter<'a> { ); let states_left_right = LeftRight::new( - self.minus_lines.iter().map(|(_, state)| state).collect(), - self.plus_lines.iter().map(|(_, state)| state).collect(), + self.minus_lines + .iter() + .map(|(_, state)| state.clone()) + .collect(), + self.plus_lines + .iter() + .map(|(_, state)| state.clone()) + .collect(), ); let bg_fill_left_right = LeftRight::new( @@ -190,17 +198,55 @@ impl<'a> Painter<'a> { // truncated do not use ANSI sequences as these would be shown after // the truncation symbol. And to be consistent, use spaces for the entire // block. + + // TODO, see prev. patch if right_panel_too_long { - BgFillWidth::CfgDefault(BgFillMethod::Spaces) + // BgFillWidth::CfgDefault(BgFillMethod::Spaces) + BgFillWidth::CfgDefault(BgFillMethod::TryAnsiSequence) } else { BgFillWidth::CfgDefault(BgFillMethod::TryAnsiSequence) }, ); + // Only set `should_wrap` to true if wrapping is wanted and lines which are + // too long are found. + // If so, remember the calculated line width and which of the lines are too + // long for later re-use. + let (should_wrap, line_width, long_lines) = if self.config.side_by_side_wrapped { + let line_width = available_line_width(&self.config, &self.line_numbers_data); + + let lines = LeftRight::new(&self.minus_lines, &self.plus_lines); + + let (should_wrap, long_lines) = side_by_side::has_long_lines(&lines, &line_width); + + (should_wrap, line_width, long_lines) + } else { + (false, LeftRight::default(), LeftRight::default()) + }; + + let (line_alignment, line_states, syntax_left_right, diff_left_right) = if should_wrap { + // Calculated for syntect::highlighting::style::Style and delta::Style + side_by_side_wrap::wrap_plusminus_block( + &self.config, + syntax_left_right, + diff_left_right, + &line_alignment, + &line_width, + &long_lines, + ) + } else { + ( + line_alignment, + states_left_right, + syntax_left_right, + diff_left_right, + ) + }; + side_by_side::paint_minus_and_plus_lines_side_by_side( syntax_left_right, diff_left_right, - states_left_right, + line_states, line_alignment, &mut self.output_buffer, self.config, @@ -264,7 +310,9 @@ impl<'a> Painter<'a> { let diff_style_sections = vec![(self.config.zero_style, lines[0].0.as_str())]; // TODO: compute style from state if self.config.side_by_side { + // `lines[0].0` so the line has the '\n' already added (as in the +- case) side_by_side::paint_zero_lines_side_by_side( + &lines[0].0, syntax_style_sections, vec![diff_style_sections], &mut self.output_buffer, @@ -366,7 +414,9 @@ impl<'a> Painter<'a> { // style: for right fill if line contains no emph sections // non_emph_style: for right fill if line contains emph sections let (style, non_emph_style) = match state { - State::HunkMinus(None) => (config.minus_style, config.minus_non_emph_style), + State::HunkMinus(None) | State::HunkMinusWrapped => { + (config.minus_style, config.minus_non_emph_style) + } State::HunkMinus(Some(raw_line)) => { // TODO: This is the second time we are parsing the ANSI sequences if let Some(ansi_term_style) = ansi::parse_first_style(raw_line) { @@ -379,8 +429,10 @@ impl<'a> Painter<'a> { (config.minus_style, config.minus_non_emph_style) } } - State::HunkZero => (config.zero_style, config.zero_style), - State::HunkPlus(None) => (config.plus_style, config.plus_non_emph_style), + State::HunkZero | State::HunkZeroWrapped => (config.zero_style, config.zero_style), + State::HunkPlus(None) | State::HunkPlusWrapped => { + (config.plus_style, config.plus_non_emph_style) + } State::HunkPlus(Some(raw_line)) => { // TODO: This is the second time we are parsing the ANSI sequences if let Some(ansi_term_style) = ansi::parse_first_style(raw_line) { |