From 6caaa60a2df6dee387914e7fa435f2c69b8458ed Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 13 Feb 2010 12:31:14 -0800 Subject: [PATCH] Fix whitespace errors with word diff enabled Whitespace errors weren't being displayed if they occurred within a region that was highlighted for word difference on a line, due to the word difference HTML code preventing the patterns from matching. Bug: issue 445 Change-Id: If4f32352aa43d7517fe7cd3f20aa8982360800a0 Signed-off-by: Shawn O. Pearce --- .../prettify/common/PrettyFormatter.java | 10 ++++++---- .../google/gerrit/prettify/client/gerrit.css | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/gerrit-prettify/src/main/java/com/google/gerrit/prettify/common/PrettyFormatter.java b/gerrit-prettify/src/main/java/com/google/gerrit/prettify/common/PrettyFormatter.java index 27273a3298..068c43a2a7 100644 --- a/gerrit-prettify/src/main/java/com/google/gerrit/prettify/common/PrettyFormatter.java +++ b/gerrit-prettify/src/main/java/com/google/gerrit/prettify/common/PrettyFormatter.java @@ -381,15 +381,17 @@ public abstract class PrettyFormatter { } private SafeHtml showTabAfterSpace(SafeHtml src) { - src = src.replaceFirst("^( *\t)", "$1"); - src = src.replaceAll("\n( *\t)", "\n$1"); + final String m = "( ( |]*>|)*\t)"; + final String r = "$1"; + src = src.replaceFirst("^" + m, r); + src = src.replaceAll("\n" + m, "\n" + r); return src; } private SafeHtml showTrailingWhitespace(SafeHtml src) { final String r = "$1$2"; - src = src.replaceAll("([ \t][ \t]*)(\r?\n)", r); - src = src.replaceFirst("([ \t][ \t]*)(\r?\n?)$", r); + src = src.replaceAll("([ \t][ \t]*)(\r?()?\n)", r); + src = src.replaceFirst("([ \t][ \t]*)(\r?()?\n?)$", r); return src; } } diff --git a/gerrit-prettify/src/main/resources/com/google/gerrit/prettify/client/gerrit.css b/gerrit-prettify/src/main/resources/com/google/gerrit/prettify/client/gerrit.css index ff9e35a354..cf39d221aa 100644 --- a/gerrit-prettify/src/main/resources/com/google/gerrit/prettify/client/gerrit.css +++ b/gerrit-prettify/src/main/resources/com/google/gerrit/prettify/client/gerrit.css @@ -26,13 +26,23 @@ border-left: 1px dotted red; } -.wse .vt { - border-left: 2px dotted black; -} - .wdd { background: #FAA; } .wdi { background: #9F9; } + +/* Use special rules for special styles contained within a whitespace + * error. For these we want the whitespace error to take precedence + * so we have to override the contained style. + */ +.wse .vt { + border-left: 2px dotted black; +} +.wse .wdd { + background: red; +} +.wse .wdi { + background: red; +}