FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit f546d38c authored by Andrew Rice's avatar Andrew Rice
Browse files

include lines which are surrounded by included lines

parent d1a34b1a
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,9 @@ import com.google.common.collect.ImmutableSet;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffFormatter;
import org.eclipse.jgit.diff.RawText;
......@@ -95,7 +97,7 @@ public class SideBySideDiffFormatter extends DiffFormatter {
}
private ImmutableSet<Integer> markLinesInScope(List<DiffRow> rows) {
ImmutableSet.Builder<Integer> indices = ImmutableSet.builder();
Set<Integer> indices = new HashSet<>();
int i = 0;
for (DiffRow row : rows) {
if (!row.getOldLine().equals(row.getNewLine())) {
......@@ -105,7 +107,14 @@ public class SideBySideDiffFormatter extends DiffFormatter {
}
i++;
}
return indices.build();
// If a line is skipped and the lines either side of it are included then we might as well
// include this line since it will take that much space just to show it.
for (int j = 0; j < i; j++) {
if (!indices.contains(j) && indices.contains(j - 1) && indices.contains(j + 1)) {
indices.add(j);
}
}
return ImmutableSet.copyOf(indices);
}
private static ImmutableList<String> lines(RawText a) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment