Skip to content

Commit 93c8280

Browse files
authored
Merge pull request oli-obk#15 from nbacquey/format_with_context
Fix bugs in `format_with_context`
2 parents 1378ab5 + 02dcef5 commit 93c8280

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/text.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ fn color_multilines(color: Colour, s: &str) -> String {
212212

213213
#[derive(Debug)]
214214
pub struct ContextConfig<'a> {
215-
context_size: usize,
216-
skipping_marker: &'a str,
215+
pub context_size: usize,
216+
pub skipping_marker: &'a str,
217217
}
218218

219219
/// Container for line-by-line text diff result. Can be pretty-printed by Display trait.
@@ -495,10 +495,10 @@ impl<'a> LineChangeset<'a> {
495495

496496
let mut next_line = 1;
497497

498-
let diff = self.diff();
498+
let mut diff = self.diff().into_iter().peekable();
499499
let mut out: Vec<String> = Vec::with_capacity(diff.len());
500500
let mut at_beginning = true;
501-
for op in diff {
501+
while let Some(op) = diff.next() {
502502
match op {
503503
basic::DiffOp::Equal(a) => match context_config {
504504
None => out.push(a.join("\n")),
@@ -531,6 +531,9 @@ impl<'a> LineChangeset<'a> {
531531
out.push(skipping_marker.to_string());
532532
next_line += lower_bound
533533
}
534+
if diff.peek().is_none() {
535+
continue;
536+
}
534537
if let Some(newlines) = self.format_equal(
535538
&lines[lower_bound..],
536539
display_line_numbers,

0 commit comments

Comments
 (0)