Cleanup CSS for side-by-side view when there are character differences
We no longer have gaps, but instead have a nice contiguous coloring region. The visual difference is night-and-day. Change-Id: I3e80a5860e62472713424dece49a018d584b3b65 Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -21,7 +21,9 @@ import org.eclipse.jgit.diff.Edit;
|
||||
import org.eclipse.jgit.diff.ReplaceEdit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class PrettyFormatter implements SparseHtmlFile {
|
||||
public static abstract class EditFilter {
|
||||
@@ -70,6 +72,7 @@ public abstract class PrettyFormatter implements SparseHtmlFile {
|
||||
protected EditFilter side;
|
||||
protected List<Edit> edits;
|
||||
protected PrettySettings settings;
|
||||
protected Set<Integer> trailingEdits;
|
||||
|
||||
private int col;
|
||||
private int lineIdx;
|
||||
@@ -89,6 +92,11 @@ public abstract class PrettyFormatter implements SparseHtmlFile {
|
||||
return content.contains(idx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTrailingEdit(int idx) {
|
||||
return trailingEdits.contains(idx);
|
||||
}
|
||||
|
||||
public void setEditFilter(EditFilter f) {
|
||||
side = f;
|
||||
}
|
||||
@@ -110,6 +118,7 @@ public abstract class PrettyFormatter implements SparseHtmlFile {
|
||||
public void format(SparseFileContent src) {
|
||||
content = new SparseFileContent();
|
||||
content.setSize(src.size());
|
||||
trailingEdits = new HashSet<Integer>();
|
||||
|
||||
String html = toHTML(src);
|
||||
|
||||
@@ -368,23 +377,33 @@ public abstract class PrettyFormatter implements SparseHtmlFile {
|
||||
final Edit edit = charEdits.get(lastIdx);
|
||||
final int b = side.getBegin(edit) - lastPos;
|
||||
final int e = side.getEnd(edit) - lastPos;
|
||||
final int modLen = Math.min(e, line.length());
|
||||
|
||||
if (c < b) {
|
||||
// There is text at the start of this line that is common
|
||||
// with the other side. Copy it with no style around it.
|
||||
//
|
||||
final int n = Math.min(b, line.length());
|
||||
buf.append(line.substring(c, n));
|
||||
c = n;
|
||||
final int cmnLen = Math.min(b, line.length());
|
||||
if (modLen == line.length()) {
|
||||
buf.openSpan();
|
||||
buf.setStyleName("wdc");
|
||||
}
|
||||
buf.append(line.substring(c, cmnLen));
|
||||
if (modLen == line.length()) {
|
||||
buf.closeSpan();
|
||||
}
|
||||
c = cmnLen;
|
||||
}
|
||||
|
||||
if (c < e) {
|
||||
final int n = Math.min(e, line.length());
|
||||
if (c < e && c < modLen) {
|
||||
buf.openSpan();
|
||||
buf.setStyleName(side.getStyleName());
|
||||
buf.append(line.substring(c, n));
|
||||
buf.append(line.substring(c, modLen));
|
||||
buf.closeSpan();
|
||||
c = n;
|
||||
if (modLen == line.length()) {
|
||||
trailingEdits.add(index);
|
||||
}
|
||||
c = modLen;
|
||||
}
|
||||
|
||||
if (e <= c) {
|
||||
|
||||
@@ -24,5 +24,8 @@ public interface SparseHtmlFile {
|
||||
public int size();
|
||||
|
||||
/** @return true if the line is valid in this sparse list. */
|
||||
public boolean contains(final int idx);
|
||||
public boolean contains(int idx);
|
||||
|
||||
/** @return true if this line ends in the middle of a character edit span. */
|
||||
public boolean hasTrailingEdit(int idx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user