Skip to content

Commit

Permalink
Make the tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
walles committed Mar 9, 2023
1 parent 4634834 commit 8beb845
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/refiner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,15 @@ fn format_split(old_text: &str, new_text: &str) -> Option<(Vec<String>, Vec<Stri
let mut new_collector = TokenCollector::create(StyledToken::new("+".to_string(), Style::New));

// Tokenize adds and removes before diffing them
let tokenized_old = tokenizer::tokenize(old_text);
let tokenized_new = tokenizer::tokenize(new_text);
let mut tokenized_old = tokenizer::tokenize(old_text);
let mut tokenized_new = tokenizer::tokenize(new_text);

// Help visualize what actually happens in "No newline at end of file" diffs
if old_text.ends_with('\n') && !new_text.ends_with('\n') {
tokenized_old.insert(tokenized_old.len() - 1, "⏎");
} else if new_text.ends_with('\n') && !old_text.ends_with('\n') {
tokenized_new.insert(tokenized_new.len() - 1, "⏎");
}

let diff = tokenized_old.diff(&tokenized_new);
match diff {
Expand Down

0 comments on commit 8beb845

Please sign in to comment.