Use hunk background colors on unified views with syntax highlighting
If syntax highlighting was turned on by the user in a unified view, use the light-red/light-green backgrounds we use in the side-by-side view to show where lines were added and removed. This may be a bit messy, but its useful to see what is going on. Change-Id: I887ad901810c03906d61432a7b67ef0b813bd9b7 Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
parent
a6658ca2d4
commit
bd277faf35
@ -132,6 +132,8 @@ public class UnifiedDiffTable extends AbstractPatchContentTable {
|
|||||||
nc.closeTr();
|
nc.closeTr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final boolean syntaxHighlighting =
|
||||||
|
script.getSettings().getPrettySettings().isSyntaxHighlighting();
|
||||||
final ArrayList<PatchLine> lines = new ArrayList<PatchLine>();
|
final ArrayList<PatchLine> lines = new ArrayList<PatchLine>();
|
||||||
for (final EditList.Hunk hunk : script.getHunks()) {
|
for (final EditList.Hunk hunk : script.getHunks()) {
|
||||||
appendHunkHeader(nc, hunk);
|
appendHunkHeader(nc, hunk);
|
||||||
@ -140,7 +142,7 @@ public class UnifiedDiffTable extends AbstractPatchContentTable {
|
|||||||
openLine(nc);
|
openLine(nc);
|
||||||
appendLineNumber(nc, hunk.getCurA());
|
appendLineNumber(nc, hunk.getCurA());
|
||||||
appendLineNumber(nc, hunk.getCurB());
|
appendLineNumber(nc, hunk.getCurB());
|
||||||
appendLineText(nc, CONTEXT, a, hunk.getCurA());
|
appendLineText(nc, false, CONTEXT, a, hunk.getCurA());
|
||||||
closeLine(nc);
|
closeLine(nc);
|
||||||
hunk.incBoth();
|
hunk.incBoth();
|
||||||
lines.add(new PatchLine(CONTEXT, hunk.getCurA(), hunk.getCurB()));
|
lines.add(new PatchLine(CONTEXT, hunk.getCurA(), hunk.getCurB()));
|
||||||
@ -149,7 +151,7 @@ public class UnifiedDiffTable extends AbstractPatchContentTable {
|
|||||||
openLine(nc);
|
openLine(nc);
|
||||||
appendLineNumber(nc, hunk.getCurA());
|
appendLineNumber(nc, hunk.getCurA());
|
||||||
padLineNumber(nc);
|
padLineNumber(nc);
|
||||||
appendLineText(nc, DELETE, a, hunk.getCurA());
|
appendLineText(nc, syntaxHighlighting, DELETE, a, hunk.getCurA());
|
||||||
closeLine(nc);
|
closeLine(nc);
|
||||||
hunk.incA();
|
hunk.incA();
|
||||||
lines.add(new PatchLine(DELETE, hunk.getCurA(), 0));
|
lines.add(new PatchLine(DELETE, hunk.getCurA(), 0));
|
||||||
@ -162,7 +164,7 @@ public class UnifiedDiffTable extends AbstractPatchContentTable {
|
|||||||
openLine(nc);
|
openLine(nc);
|
||||||
padLineNumber(nc);
|
padLineNumber(nc);
|
||||||
appendLineNumber(nc, hunk.getCurB());
|
appendLineNumber(nc, hunk.getCurB());
|
||||||
appendLineText(nc, INSERT, b, hunk.getCurB());
|
appendLineText(nc, syntaxHighlighting, INSERT, b, hunk.getCurB());
|
||||||
closeLine(nc);
|
closeLine(nc);
|
||||||
hunk.incB();
|
hunk.incB();
|
||||||
lines.add(new PatchLine(INSERT, 0, hunk.getCurB()));
|
lines.add(new PatchLine(INSERT, 0, hunk.getCurB()));
|
||||||
@ -308,7 +310,8 @@ public class UnifiedDiffTable extends AbstractPatchContentTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void appendLineText(final SafeHtmlBuilder m,
|
private void appendLineText(final SafeHtmlBuilder m,
|
||||||
final PatchLine.Type type, final SparseHtmlFile src, final int i) {
|
boolean syntaxHighlighting, final PatchLine.Type type,
|
||||||
|
final SparseHtmlFile src, final int i) {
|
||||||
final SafeHtml text = src.getSafeHtmlLine(i);
|
final SafeHtml text = src.getSafeHtmlLine(i);
|
||||||
m.openTd();
|
m.openTd();
|
||||||
m.addStyleName(Gerrit.RESOURCES.css().diffText());
|
m.addStyleName(Gerrit.RESOURCES.css().diffText());
|
||||||
@ -320,11 +323,17 @@ public class UnifiedDiffTable extends AbstractPatchContentTable {
|
|||||||
break;
|
break;
|
||||||
case DELETE:
|
case DELETE:
|
||||||
m.addStyleName(Gerrit.RESOURCES.css().diffTextDELETE());
|
m.addStyleName(Gerrit.RESOURCES.css().diffTextDELETE());
|
||||||
|
if (syntaxHighlighting) {
|
||||||
|
m.addStyleName(Gerrit.RESOURCES.css().fileLineDELETE());
|
||||||
|
}
|
||||||
m.append("-");
|
m.append("-");
|
||||||
m.append(text);
|
m.append(text);
|
||||||
break;
|
break;
|
||||||
case INSERT:
|
case INSERT:
|
||||||
m.addStyleName(Gerrit.RESOURCES.css().diffTextINSERT());
|
m.addStyleName(Gerrit.RESOURCES.css().diffTextINSERT());
|
||||||
|
if (syntaxHighlighting) {
|
||||||
|
m.addStyleName(Gerrit.RESOURCES.css().fileLineINSERT());
|
||||||
|
}
|
||||||
m.append("+");
|
m.append("+");
|
||||||
m.append(text);
|
m.append(text);
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user