Skip to content

Commit

Permalink
Merge branch 'johan/illustrate-eol-at-eof'
Browse files Browse the repository at this point in the history
  • Loading branch information
walles committed Mar 9, 2023
2 parents f6c6807 + 8beb845 commit 15ee35e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ If you want to test the release script without actually releasing anything, do:

## Misc

- Render ESC characters in the diff as Unicode ␛
- `--help`: Only print installing-into-`$PATH` help if we aren't already being
executed from inside of the `$PATH`
- Do `git show 5e0a1b2b13528f40299e78e3bfa590d9f96637af` and scroll to the end.
Expand Down
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
3 changes: 3 additions & 0 deletions testdata/add-trailing-newline.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-apor
\ No newline at end of file
+apor
3 changes: 3 additions & 0 deletions testdata/add-trailing-newline.riff-output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-apor
\ No newline at end of file
+apor⏎
4 changes: 4 additions & 0 deletions testdata/changed-lines-without-newlines.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-apor
\ No newline at end of file
+aporna
\ No newline at end of file
4 changes: 4 additions & 0 deletions testdata/changed-lines-without-newlines.riff-output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-apor
\ No newline at end of file
+aporna
\ No newline at end of file
2 changes: 1 addition & 1 deletion testdata/remove-trailing-newline.riff-output
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-apor
-apor⏎
+apor
\ No newline at end of file

0 comments on commit 15ee35e

Please sign in to comment.