Skip to content

Commit

Permalink
Context highlight more parts of conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
walles committed Oct 7, 2024
1 parent f558229 commit 78f5a86
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
10 changes: 3 additions & 7 deletions src/conflicts_highlighter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl ConflictsHighlighter {
let c1_or_newline = if c1.is_empty() { "\n" } else { &c1 };
let c2_or_newline = if c2.is_empty() { "\n" } else { &c2 };
let (c1_tokens, c2_tokens, _, _) =
refiner::to_highlighted_tokens(c1_or_newline, c2_or_newline, false);
refiner::to_highlighted_tokens(c1_or_newline, c2_or_newline, true);

let c1_style = if base_header.is_empty() {
LINE_STYLE_OLD
Expand Down Expand Up @@ -266,9 +266,7 @@ impl ConflictsHighlighter {
if c1.is_empty() {
// In the base, show only diffs vs c2
base_vs_c1_tokens.iter_mut().for_each(|token| {
if token.style == Style::HighlightedChange {
token.style = Style::Plain;
}
token.style = Style::Context;
});
}
let highlighted_c1 =
Expand All @@ -280,9 +278,7 @@ impl ConflictsHighlighter {
if c2.is_empty() {
// In the base, show only diffs vs c1
base_vs_c2_tokens.iter_mut().for_each(|token| {
if token.style == Style::HighlightedChange {
token.style = Style::Plain;
}
token.style = Style::Context;
});
}
let highlighted_c2 =
Expand Down
6 changes: 3 additions & 3 deletions src/refiner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fn is_whitepace_replacement(old_run: &[&str], new_run: &[&str]) -> bool {
pub fn to_highlighted_tokens(
old_text: &str,
new_text: &str,
is_three_way_conflict: bool,
is_conflict: bool,
) -> (Vec<StyledToken>, Vec<StyledToken>, bool, bool) {
// Find diffs between adds and removals
let mut old_tokens = Vec::new();
Expand Down Expand Up @@ -310,13 +310,13 @@ pub fn to_highlighted_tokens(

// Refine old tokens highlighting
bridge_consecutive_highlighted_tokens(&mut old_tokens);
if is_three_way_conflict {
if is_conflict {
contextualize_unhighlighted_lines(&mut old_tokens);
}

// Refine new tokens highlighting
bridge_consecutive_highlighted_tokens(&mut new_tokens);
if is_three_way_conflict {
if is_conflict {
contextualize_unhighlighted_lines(&mut new_tokens);
}
errorlight_trailing_whitespace(&mut new_tokens);
Expand Down

0 comments on commit 78f5a86

Please sign in to comment.