The Unified and Autonomous Development Platform
Modify TextDiffPanel to only display context lines of diffs and comments by default, instead of displaying full text.
robin shine2e219fb5e45c
diff --git a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffChunk.java b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffChunk.javadeleted file mode 100644index 1df8075786..0000000000--- a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffChunk.java+++ /dev/null@@ -1,63 +0,0 @@-package com.pmease.commons.util.diff;--import java.io.Serializable;-import java.util.ArrayList;-import java.util.Collections;-import java.util.List;--@SuppressWarnings("serial")-public class DiffChunk implements Serializable {-- private final int start1;-- private final int start2;-- public final List<DiffLine> diffLines;-- public DiffChunk(int start1, int start2, List<DiffLine> diffLines) {- this.start1 = start1;- this.start2 = start2;- this.diffLines = new ArrayList<>(diffLines);- }-- /**- * Get starting row number of original part of this diff chunk. <tt>0</tt> represents- * the first row.- *- * @return- * starting row number of original part of the diff chunk- */- public int getStart1() {- return start1;- }-- /**- * Get starting row number of revised part of this diff chunk. <tt>0</tt> represents- * the first row.- *- * @return- * starting row number of revised part of the diff chunk- */- public int getStart2() {- return start2;- }-- public List<DiffLine> getDiffLines() {- return Collections.unmodifiableList(diffLines);- }-- /**- * Get string representation of this diff chunk. It will mimics the unified diff format,- * so row number will be increased by one, that is, the first row will be represented- * by <tt>1</tt>.- */- @Override- public String toString() {- StringBuffer buffer = new StringBuffer();- buffer.append("@@ -").append(start1+1).append(" +").append(start2+1).append(" @@\n");- for (DiffLine line: diffLines)- buffer.append(line).append("\n");- return buffer.toString();- }--}diff --git a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffHunk.java b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffHunk.javanew file mode 100644index 0000000000..a06a8fa982--- /dev/null+++ b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffHunk.java@@ -0,0 +1,104 @@+package com.pmease.commons.util.diff;++import java.io.Serializable;+import java.util.List;++@SuppressWarnings("serial")+public class DiffHunk implements Serializable {++ private int oldStart, oldEnd, newStart, newEnd;++ private final List<DiffLine> diffLines;++ public DiffHunk(int oldStart, int newStart, List<DiffLine> diffLines) {+ this.oldStart = oldStart;+ this.newStart = newStart;+ this.diffLines = diffLines;++ oldEnd = oldStart;+ newEnd = newStart;+ for (DiffLine diffLine: diffLines) {+ if (diffLine.getAction() == DiffLine.Action.ADD) {+ newEnd++;+ } else if (diffLine.getAction() == DiffLine.Action.DELETE) {+ oldEnd++;+ } else {+ oldEnd++;+ newEnd++;+ }+ }+ }++ /**+ * Get starting row number of original part of this diff chunk. <tt>0</tt> represents+ * the first row.+ *+ * @return+ * starting row number of original part of the diff chunk+ */+ public int getOldStart() {+ return oldStart;+ }++ /**+ * Get starting row number of revised part of this diff chunk. <tt>0</tt> represents+ * the first row.+ *+ * @return+ * starting row number of revised part of the diff chunk+ */+ public int getNewStart() {+ return newStart;+ }++ public int getOldEnd() {+ return oldEnd;+ }++ public void setOldEnd(int oldEnd) {+ this.oldEnd = oldEnd;+ }++ public int getNewEnd() {+ return newEnd;+ }++ public void setNewEnd(int newEnd) {+ this.newEnd = newEnd;+ }++ public void setOldStart(int oldStart) {+ this.oldStart = oldStart;+ }++ public void setNewStart(int newStart) {+ this.newStart = newStart;+ }++ public List<DiffLine> getDiffLines() {+ return diffLines;+ }++ /**+ * Get string representation of this diff chunk. It will mimics the unified diff format,+ * so row number will be increased by one, that is, the first row will be represented+ * by <tt>1</tt>.+ */+ @Override+ public String toString() {+ StringBuffer buffer = new StringBuffer(describe(oldStart, newStart, oldEnd, newEnd));+ buffer.append("\n");+ for (DiffLine line: diffLines)+ buffer.append(line).append("\n");+ return buffer.toString();+ }++ public static String describe(int oldStart, int newStart, int oldEnd, int newEnd) {+ StringBuffer buffer = new StringBuffer();+ int oldCount = oldEnd-oldStart;+ int newCount = newEnd-newStart;+ buffer.append("@@ -").append(oldCount!=0?oldStart+1:0).append(",").append(oldCount)+ .append(" +").append(newCount!=0?newStart+1:0).append(",").append(newCount).append(" @@");+ return buffer.toString();+ }+}diff --git a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.java b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.javaindex d33c009e2f..e03b5b1d59 100644--- a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.java+++ b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.java@@ -2,8 +2,10 @@ package com.pmease.commons.util.diff;import java.util.ArrayList;import java.util.HashMap;+import java.util.HashSet;import java.util.List;import java.util.Map;+import java.util.Set;import javax.annotation.Nullable;@@ -161,113 +163,127 @@ public class DiffUtils {return lineMapping;}- public static List<DiffChunk> diffAsChunks(List<String> original, List<String> revised,- PartialSplitter wordSplitter, int chunkMargin) {- return chunksOf(diff(original, revised, wordSplitter), chunkMargin);+ public static List<DiffHunk> diffAsHunks(List<String> original, List<String> revised,+ PartialSplitter wordSplitter, int contextSize) {+ return hunksOf(diff(original, revised, wordSplitter), contextSize);}- public static List<DiffChunk> chunksOf(List<DiffLine> diffLines, int contextLines) {+ public static List<DiffHunk> diffAsHunks(List<String> original, List<String> revised,+ PartialSplitter wordSplitter, Set<Integer> additionalOldLinesToPreserve,+ Set<Integer> additionalNewLinesToPreserve, int contextSize) {+ return hunksOf(diff(original, revised, wordSplitter), additionalOldLinesToPreserve,+ additionalNewLinesToPreserve, contextSize);+ }++ public static List<DiffHunk> hunksOf(List<DiffLine> diffLines, int contextSize) {+ return hunksOf(diffLines, new HashSet<Integer>(), new HashSet<Integer>(), contextSize);+ }++ public static List<DiffHunk> hunksOf(List<DiffLine> diffLines, Set<Integer> additionalOldLinesToPreserve,+ Set<Integer> additionalNewLinesToPreserve, int contextSize) {List<RemovableDiffLine> removableDiffLines = new ArrayList<>();for (DiffLine diffLine: diffLines)removableDiffLines.add(new RemovableDiffLine(diffLine, false));- int equalCount = 0;+ int contextCount = 0;int index = 0;for (RemovableDiffLine each: removableDiffLines) {- if (each.diffLine.getAction() == Action.EQUAL) {- equalCount++;- } else if (index == equalCount) {- for (int i=index-equalCount; i<index-contextLines; i++)+ if (each.diffLine.getAction() == Action.EQUAL+ && !additionalOldLinesToPreserve.contains(each.diffLine.getOldLineNo())+ && !additionalNewLinesToPreserve.contains(each.diffLine.getNewLineNo())) {+ contextCount++;+ } else if (index == contextCount) {+ for (int i=index-contextCount; i<index-contextSize; i++)removableDiffLines.get(i).removed = true;- equalCount = 0;+ contextCount = 0;} else {- for (int i=index-equalCount+contextLines; i<index-contextLines; i++)+ for (int i=index-contextCount+contextSize; i<index-contextSize; i++)removableDiffLines.get(i).removed = true;- equalCount = 0;+ contextCount = 0;}index++;}- for (int i=index-equalCount+contextLines; i<index; i++)+ for (int i=index-contextCount+contextSize; i<index; i++)removableDiffLines.get(i).removed = true;- List<DiffChunk> diffChunks = new ArrayList<>();+ List<DiffHunk> hunks = new ArrayList<>();- int start1 = 0;- int start2 = 0;- DiffChunkBuilder chunkBuilder = new DiffChunkBuilder();+ int oldStart = 0;+ int newStart = 0;+ DiffHunkBuilder hunkBuilder = new DiffHunkBuilder();for (RemovableDiffLine each: removableDiffLines) {if (!each.removed) {- if (chunkBuilder.diffUnits.isEmpty()) {- chunkBuilder.start1 = start1;- chunkBuilder.start2 = start2;+ if (hunkBuilder.diffLines.isEmpty()) {+ hunkBuilder.oldStart = oldStart;+ hunkBuilder.newStart = newStart;}- chunkBuilder.diffUnits.add(each.diffLine);+ hunkBuilder.diffLines.add(each.diffLine);} else {- if (!chunkBuilder.diffUnits.isEmpty()) {- diffChunks.add(chunkBuilder.build());- chunkBuilder = new DiffChunkBuilder();+ if (!hunkBuilder.diffLines.isEmpty()) {+ hunks.add(hunkBuilder.build());+ hunkBuilder = new DiffHunkBuilder();}}if (each.diffLine.getAction() == Action.ADD) {- start2++;+ newStart++;} else if (each.diffLine.getAction() == Action.DELETE) {- start1++;+ oldStart++;} else {- start1++;- start2++;+ oldStart++;+ newStart++;}}- if (!chunkBuilder.diffUnits.isEmpty())- diffChunks.add(chunkBuilder.build());+ if (!hunkBuilder.diffLines.isEmpty())+ hunks.add(hunkBuilder.build());- return diffChunks;+ return hunks;}- public static List<DiffChunk> parseUnifiedDiff(List<String> unifiedDiff) {- List<DiffChunk> chunks = new ArrayList<>();+ public static List<DiffHunk> parseUnifiedDiff(List<String> unifiedDiff) {+ List<DiffHunk> hunks = new ArrayList<>();- DiffChunkBuilder chunkBuilder = null;+ DiffHunkBuilder hunkBuilder = null;for (String line : unifiedDiff) {if (line.startsWith("@@")) {- if (chunkBuilder != null)- chunks.add(chunkBuilder.build());- chunkBuilder = new DiffChunkBuilder();+ if (hunkBuilder != null)+ hunks.add(hunkBuilder.build());+ hunkBuilder = new DiffHunkBuilder();line = StringUtils.substringBefore(line.substring(4), " @@");String first = StringUtils.substringBefore(line, " +");String second = StringUtils.substringAfter(line, " +");if (first.indexOf(",") != -1) {- chunkBuilder.start1 = Integer.parseInt(StringUtils.substringBefore(first, ",")) - 1;+ hunkBuilder.oldStart = Integer.parseInt(StringUtils.substringBefore(first, ",")) - 1;} else {- chunkBuilder.start1 = Integer.parseInt(first) - 1;+ hunkBuilder.oldStart = Integer.parseInt(first) - 1;}if (second.indexOf(",") != -1) {- chunkBuilder.start2 = Integer.parseInt(StringUtils.substringBefore(second, ",")) - 1;+ hunkBuilder.newStart = Integer.parseInt(StringUtils.substringBefore(second, ",")) - 1;} else {- chunkBuilder.start2 = Integer.parseInt(second) - 1;+ hunkBuilder.newStart = Integer.parseInt(second) - 1;}- chunkBuilder.current1 = chunkBuilder.start1;- chunkBuilder.current2 = chunkBuilder.start2;- } else if (chunkBuilder != null) {+ hunkBuilder.current1 = hunkBuilder.oldStart;+ hunkBuilder.current2 = hunkBuilder.newStart;+ } else if (hunkBuilder != null) {if (line.startsWith("+")) {- chunkBuilder.diffUnits.add(new DiffLine(Action.ADD, line.substring(1),- chunkBuilder.current1, chunkBuilder.current2));- chunkBuilder.current2++;+ hunkBuilder.diffLines.add(new DiffLine(Action.ADD, line.substring(1),+ hunkBuilder.current1, hunkBuilder.current2));+ hunkBuilder.current2++;} else if (line.startsWith("-")) {- chunkBuilder.diffUnits.add(new DiffLine(Action.DELETE, line.substring(1),- chunkBuilder.current1, chunkBuilder.current2));- chunkBuilder.current1++;+ hunkBuilder.diffLines.add(new DiffLine(Action.DELETE, line.substring(1),+ hunkBuilder.current1, hunkBuilder.current2));+ hunkBuilder.current1++;} else if (line.startsWith(" ")) {- chunkBuilder.diffUnits.add(new DiffLine(Action.EQUAL, line.substring(1),- chunkBuilder.current1, chunkBuilder.current2));- chunkBuilder.current1++;- chunkBuilder.current2++;+ hunkBuilder.diffLines.add(new DiffLine(Action.EQUAL, line.substring(1),+ hunkBuilder.current1, hunkBuilder.current2));+ hunkBuilder.current1++;+ hunkBuilder.current2++;}}}- if (chunkBuilder != null) chunks.add(chunkBuilder.build());+ if (hunkBuilder != null) hunks.add(hunkBuilder.build());- return chunks;+ return hunks;}private static TokensToCharsResult tokensToChars(List<String> tokens1, List<String> tokens2) {@@ -333,15 +349,15 @@ public class DiffUtils {}}- private static class DiffChunkBuilder {- private int start1, start2;+ private static class DiffHunkBuilder {+ private int oldStart, newStart;private int current1, current2;- private List<DiffLine> diffUnits = new ArrayList<>();+ private List<DiffLine> diffLines = new ArrayList<>();- private DiffChunk build() {- return new DiffChunk(start1, start2, diffUnits);+ private DiffHunk build() {+ return new DiffHunk(oldStart, newStart, diffLines);}}diff --git a/commons.util/src/test/java/com/pmease/commons/util/diff/DiffUtilsTest.java b/commons.util/src/test/java/com/pmease/commons/util/diff/DiffUtilsTest.javaindex 979c213832..65aed5348c 100644--- a/commons.util/src/test/java/com/pmease/commons/util/diff/DiffUtilsTest.java+++ b/commons.util/src/test/java/com/pmease/commons/util/diff/DiffUtilsTest.java@@ -5,11 +5,13 @@ import static org.junit.Assert.assertTrue;import java.util.ArrayList;import java.util.Arrays;+import java.util.HashSet;import java.util.List;import java.util.Map;import org.junit.Test;+import com.google.common.collect.Sets;import com.pmease.commons.util.diff.DiffLine.Action;public class DiffUtilsTest {@@ -50,7 +52,7 @@ public class DiffUtilsTest {}@Test- public void shouldGenerateDiffChunksCorrectly() {+ public void shouldGenerateDiffHunksCorrectly() {List<String> text1 = new ArrayList<>();text1.add("this is the 1st line");text1.add("this is the 2nd line");@@ -76,10 +78,10 @@ public class DiffUtilsTest {text2.add("this is the 10th line");text2.add("this is the 11th line");- List<DiffChunk> diffChunks = DiffUtils.diffAsChunks(text1, text2, null, 3);- assertEquals(1, diffChunks.size());+ List<DiffHunk> diffHunks = DiffUtils.diffAsHunks(text1, text2, null, 3);+ assertEquals(1, diffHunks.size());assertEquals(- "@@ -1 +1 @@\n" ++ "@@ -1,10 +1,11 @@\n" +" this is the 1st line\n" +"-this is the 2nd line\n" +"+this is the second line\n" +@@ -93,32 +95,54 @@ public class DiffUtilsTest {"+this is the nineth line\n" +" this is the 10th line\n" +"+this is the 11th line\n",- diffChunks.get(0).toString());+ diffHunks.get(0).toString());- diffChunks = DiffUtils.diffAsChunks(text1, text2, null, 2);- assertEquals(2, diffChunks.size());+ diffHunks = DiffUtils.diffAsHunks(text1, text2, null, 2);+ assertEquals(2, diffHunks.size());assertEquals(- "@@ -1 +1 @@\n" ++ "@@ -1,4 +1,4 @@\n" +" this is the 1st line\n" +"-this is the 2nd line\n" +"+this is the second line\n" +" this is the 3rd line\n" +" this is the 4th line\n",- diffChunks.get(0).toString());+ diffHunks.get(0).toString());assertEquals(- "@@ -7 +7 @@\n" ++ "@@ -7,4 +7,5 @@\n" +" this is the 7th line\n" +" this is the 8th line\n" +"-this is the 9th line\n" +"+this is the nineth line\n" +" this is the 10th line\n" +"+this is the 11th line\n",- diffChunks.get(1).toString());- diffChunks = DiffUtils.diffAsChunks(text1, text2, null, 0);- assertEquals(3, diffChunks.size());- assertEquals(2, diffChunks.get(0).getDiffLines().size());- assertEquals(2, diffChunks.get(1).getDiffLines().size());- assertEquals(1, diffChunks.get(2).getDiffLines().size());+ diffHunks.get(1).toString());++ diffHunks = DiffUtils.diffAsHunks(text1, text2, null, new HashSet<Integer>(), Sets.newHashSet(4), 1);+ assertEquals(2, diffHunks.size());+ assertEquals(+ "@@ -1,6 +1,6 @@\n" ++ " this is the 1st line\n" ++ "-this is the 2nd line\n" ++ "+this is the second line\n" ++ " this is the 3rd line\n" ++ " this is the 4th line\n" ++ " this is the 5th line\n" ++ " this is the 6th line\n",+ diffHunks.get(0).toString());+ assertEquals(+ "@@ -8,3 +8,4 @@\n" ++ " this is the 8th line\n" ++ "-this is the 9th line\n" ++ "+this is the nineth line\n" ++ " this is the 10th line\n" ++ "+this is the 11th line\n",+ diffHunks.get(1).toString());++ diffHunks = DiffUtils.diffAsHunks(text1, text2, null, 0);+ assertEquals(3, diffHunks.size());+ assertEquals(2, diffHunks.get(0).getDiffLines().size());+ assertEquals(2, diffHunks.get(1).getDiffLines().size());+ assertEquals(1, diffHunks.get(2).getDiffLines().size());text1 = new ArrayList<>();text1.add("this is the 1st line");@@ -144,12 +168,12 @@ public class DiffUtilsTest {text2.add("this is the 9th line");text2.add("this is the 10th line");- diffChunks = DiffUtils.diffAsChunks(text1, text2, null, 3);- assertEquals(1, diffChunks.size());+ diffHunks = DiffUtils.diffAsHunks(text1, text2, null, 3);+ assertEquals(1, diffHunks.size());- diffChunks = DiffUtils.diffAsChunks(text1, text2, null, 0);- assertEquals(1, diffChunks.size());- assertEquals(2, diffChunks.get(0).getDiffLines().size());+ diffHunks = DiffUtils.diffAsHunks(text1, text2, null, 0);+ assertEquals(1, diffHunks.size());+ assertEquals(2, diffHunks.get(0).getDiffLines().size());}@Test@@ -167,16 +191,16 @@ public class DiffUtilsTest {text2.add("this is the 3rd line");text2.add("this is the 4th line");- List<DiffChunk> diffChunks = DiffUtils.diffAsChunks(text1, text2, new WordSplitter(), 100);+ List<DiffHunk> diffHunks = DiffUtils.diffAsHunks(text1, text2, new WordSplitter(), 100);assertEquals(- "@@ -1 +1 @@\n" ++ "@@ -1,4 +1,5 @@\n" +" this is the 1st line\n" +"-this is the *2nd* line\n" +"+this is the *11th* line\n" +"+this is the second line\n" +" this is the 3rd line\n" +" this is the 4th line\n",- diffChunks.get(0).toString());+ diffHunks.get(0).toString());text1 = new ArrayList<>();text1.add("this is the 1st line");@@ -191,17 +215,17 @@ public class DiffUtilsTest {text2.add("this is the 3rd line");text2.add("I do not think this works");- diffChunks = DiffUtils.diffAsChunks(text1, text2, new WordSplitter(), 100);+ diffHunks = DiffUtils.diffAsHunks(text1, text2, new WordSplitter(), 100);assertEquals(- "@@ -1 +1 @@\n" ++ "@@ -1,4 +1,5 @@\n" +" this is the 1st line\n" +"-this is the *2nd* line\n" +- "+I do not think this is the 11th line\n" +- "+this is the *second* line\n" ++ "+*I** **do** **not** **think** *this is the *11th* line\n" ++ "+this is the second line\n" +" this is the 3rd line\n" +"-this is the 4th line\n" +"+I do not think this works\n",- diffChunks.get(0).toString());+ diffHunks.get(0).toString());}@Testdiff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/AbstractWicketConfig.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/AbstractWicketConfig.javaindex 7e17b3a11b..ce058e8b9d 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/AbstractWicketConfig.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/AbstractWicketConfig.java@@ -32,6 +32,8 @@ public abstract class AbstractWicketConfig extends WebApplication {getMarkupSettings().setDefaultMarkupEncoding("UTF-8");getMarkupSettings().setStripComments(true);getMarkupSettings().setStripWicketTags(true);++ getPageSettings().setRecreateMountedPagesAfterExpiry(false);getStoreSettings().setFileStoreFolder(Bootstrap.getTempDir());@@ -59,8 +61,10 @@ public abstract class AbstractWicketConfig extends WebApplication {if (page.getSessionFeedback().anyMessage())target.add(page.getSessionFeedback());- for (Component component: map.values())+ for (Component component: map.values()) {+ target.prependJavaScript(String.format("$('#%s').trigger('sticky_kit:detach');", component.getMarkupId()));target.appendJavaScript((String.format("$(document).trigger('replace', '%s');", component.getMarkupId())));+ }target.appendJavaScript("$(document.body).trigger('sticky_kit:recalc')");}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.cssindex d39c0f529c..443c6cbd52 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css@@ -771,23 +771,31 @@ h2.section-title { margin: 18px 0; font-size: 16px; }.text-diff>.panel-heading .pull-right {margin-left: 12px;}.text-diff>.body {overflow: auto;}-.table-diff .line.content>td.line-no {color: #999; width: 1%; text-align: right; white-space: nowrap;}-.table-diff .line.content td.text {font-family: Consolas,"Liberation Mono",Menlo,Courier,monospace;- color: #333; overflow: visible; white-space: pre;}+.table-diff .line.diff>td.line-no {color: #999; width: 1%; text-align: right; white-space: nowrap;}+.table-diff .line.diff td.text, .table-diff .hunk-head td.content {+ font-family: Consolas,"Liberation Mono",Menlo,Courier,monospace;}+.table-diff .line.diff td.text {color: #333; overflow: visible; white-space: pre;}.table-diff {font-size: 12px; position:relative;}.table-diff>tbody>tr>td {padding: 2px 8px;}.table-diff>tbody>tr>td.text, .table-diff>tbody>tr>td.detail, .table-diff>tbody>tr>td.new {border-left: 1px solid #E5E5E5;}-.table-diff .old.line.content>td.line-no {background: #faa; color: #8f0000;}-.table-diff .old.line.content {background: #fdd;}-.table-diff .old.line.content .emphasize {background: #FC9090;}-.table-diff .new.line.content {background: #cfc;}-.table-diff .new.line.content>td.line-no {background: #89FB89; color: #007f00;}-.table-diff .new.line.content .emphasize {background: #07C907;}-.table-diff .line.content:hover {background: #fea; }-.table-diff .line.content:hover>td.line-no {background: #FBDE6D;}+.table-diff .old.line.diff>td.line-no {background: #faa; color: #8f0000;}+.table-diff .old.line.diff {background: #fdd;}+.table-diff .old.line.diff .emphasize {background: #FC9090;}+.table-diff .new.line.diff {background: #cfc;}+.table-diff .new.line.diff>td.line-no {background: #89FB89; color: #007f00;}+.table-diff .new.line.diff .emphasize {background: #07C907;}+.table-diff .line.diff:hover {background: #fea; }+.table-diff .line.diff:hover>td.line-no, .table-diff .line.hunk-head:hover .action {background: #FBDE6D;}+.table-diff .hunk-head, .equal.hunk-line>td.info {color: #999;}+.table-diff .hunk-head a {display: block; color: #999;}+.table-diff .hunk-head a:hover {color: #444;}+.table-diff .hunk-head td.action {text-align: center;}+.table-diff .hunk-head {background: none repeat scroll 0 0 #eef;}+.table-diff table.content {width: 100%;}-.table-diff .line.comments>td {padding: 0 12px; border: 3px solid #DDD;}+.table-diff .line.comments>td {padding: 0 12px; border-top: 1px solid #DDD;+ border-bottom: 1px solid #DDD; background: #FFFAF5;}.table-diff .line.comments td.avatar .concerned-comment {margin-top: 12px; font-size: 36px; color: #E7C325;}form#add-comment {margin: 16px 4px;}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/js/page.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/js/page.jsindex e6bbf3f316..660d013b8f 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/js/page.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/js/page.js@@ -155,6 +155,10 @@ var gitplex = {var $line = $("#diffline-" + index);$line.next().remove();$line.find("a.add-comment").show();+ },+ afterRemove: function(index) {+ $("#comment-diffline-" + index).closest("tr").remove();+ $("#diffline-" + index).find("a.add-comment").show();}}};diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.htmlindex fb9dee4660..d1f558082b 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html@@ -9,13 +9,16 @@<span wicket:id="diffOptionsTrigger" class="btn btn-sm btn-default" title="Diff options"><i class="fa fa-gear"></i> <i class="caret"></i></span><div wicket:id="diffOptions"></div></div>- <div wicket:id="commentActions" class="btn-group pull-right">+ <div class="pull-right">+ <span wicket:id="displayFull" class="btn btn-sm btn-default" title="Expand to display full file"><i class="fa fa-file-txt"></i> </span>+ </div>+ <div class="btn-group pull-right"><span wicket:id="prevComment" class="btn btn-default btn-sm comments-nav" title="Previous commented line"><i class="fa fa-arrow-up"></i> <i class="fa fa-comments"></i></span><span wicket:id="nextComment" class="btn btn-default btn-sm comments-nav" title="Next commented line"><i class="fa fa-arrow-down"></i> <i class="fa fa-comments"></i></span><span wicket:id="showComments" class="btn btn-default btn-sm show-comments" title="Show comments"><i class="fa fa-eye-open"></i> <i class="fa fa-comments"></i></span><span wicket:id="hideComments" class="btn btn-default btn-sm hide-comments" title="Hide comments"><i class="fa fa-eye-slash"></i> <i class="fa fa-comments"></i></span></div>- <div class="btn-group pull-right">+ <div wicket:id="diffNavs" class="btn-group pull-right"><span wicket:id="prevDiff" class="btn btn-default btn-sm" title="Previous changed block"><i class="fa fa-arrow-up"></i> <i class="fa fa-diff"></i></span><span wicket:id="nextDiff" class="btn btn-default btn-sm" title="Next changed block"><i class="fa fa-arrow-down"></i> <i class="fa fa-diff"></i></span></div>@@ -24,7 +27,22 @@</div></div>- <wicket:container wicket:id="diffs"></wicket:container>+ <table id="diffs-table" class="table-diff">+ <wicket:container wicket:id="hunks">+ <tr wicket:id="head" class="line hunk-head">+ <td colspan="2" class="action">+ <a wicket:id="expand"><i class="fa fa-expand"></i></a>+ </td>+ <td class="content"><span wicket:id="content"></span></td>+ </tr>+ <wicket:container wicket:id="body"></wicket:container>+ </wicket:container>+ <tr wicket:id="lastRow" class="line hunk-head">+ <td colspan="2" class="action"><a wicket:id="expand"><i class="fa fa-expand"></i></a></td>+ <td class="content"> </td>+ </tr>+ </table>+<div id="comments-placeholder" class="hidden"><table wicket:id="lines" class="comments"><tr wicket:id="comments">diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.javaindex 46bb728bf7..ba50bc0ab9 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java@@ -13,6 +13,9 @@ import java.util.Map;import javax.annotation.Nullable;+import jersey.repackaged.com.google.common.collect.Lists;++import org.apache.commons.lang3.StringUtils;import org.apache.shiro.SecurityUtils;import org.apache.wicket.Component;import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;@@ -40,12 +43,14 @@ import org.apache.wicket.util.string.Strings;import com.google.common.base.Preconditions;import com.pmease.commons.git.BlobText;import com.pmease.commons.git.RevAwareChange;+import com.pmease.commons.util.diff.DiffHunk;import com.pmease.commons.util.diff.DiffLine;import com.pmease.commons.util.diff.DiffUtils;import com.pmease.commons.util.diff.Partial;import com.pmease.commons.util.diff.WordSplitter;import com.pmease.commons.wicket.behavior.ScrollBehavior;import com.pmease.commons.wicket.behavior.StickyBehavior;+import com.pmease.commons.wicket.behavior.TooltipBehavior;import com.pmease.commons.wicket.behavior.menu.CheckMenuItem;import com.pmease.commons.wicket.behavior.menu.MenuBehavior;import com.pmease.commons.wicket.behavior.menu.MenuItem;@@ -71,12 +76,10 @@ public class TextDiffPanel extends Panel implements InlineContextAware {private enum DiffOption {IGNORE_NOTHING, IGNORE_EOL, IGNORE_EOL_SPACES, IGNORE_CHANGE_SPACES};- private static final int SCROLL_MARGIN = 50;-- private static final String COMMENT_ACTIONS_ID = "commentActions";-- private static final String HEAD_ID = "head";+ private static final int SCROLL_MARGIN = 100;+ private static final int CONTEXT_SIZE = 5;+private final IModel<Repository> repoModel;private final BlobText oldText;@@ -101,98 +104,32 @@ public class TextDiffPanel extends Panel implements InlineContextAware {private List<DiffLine> diffs;- private final IModel<Map<Integer, List<InlineComment>>> commentsModel =- new LoadableDetachableModel<Map<Integer, List<InlineComment>>>() {-- @Override- protected Map<Integer, List<InlineComment>> load() {- Map<Integer, Integer> oldLinesMap = new HashMap<>();- Map<Integer, Integer> newLinesMap = new HashMap<>();-- int index = 0;- for (DiffLine diff: diffs) {- oldLinesMap.put(diff.getOldLineNo(), index);- newLinesMap.put(diff.getNewLineNo(), index);- index++;- }-- Map<Integer, List<InlineComment>> comments = new HashMap<>();- for (Map.Entry<Integer, List<InlineComment>> entry: commentSupport.getOldComments().entrySet()) {- int diffLineNo = oldLinesMap.get(entry.getKey());- List<InlineComment> lineComments = comments.get(diffLineNo);- if (lineComments == null) {- lineComments = new ArrayList<>();- comments.put(diffLineNo, lineComments);- }- lineComments.addAll(entry.getValue());- }- for (Map.Entry<Integer, List<InlineComment>> entry: commentSupport.getNewComments().entrySet()) {- int diffLineNo = newLinesMap.get(entry.getKey());- List<InlineComment> lineComments = comments.get(diffLineNo);- if (lineComments == null) {- lineComments = new ArrayList<>();- comments.put(diffLineNo, lineComments);- }- lineComments.addAll(entry.getValue());- }-- for (List<InlineComment> lineComments: comments.values()) {- Collections.sort(lineComments, new Comparator<InlineComment>() {+ private List<DiffHunk> hunks;++ private boolean identical;- @Override- public int compare(InlineComment o1, InlineComment o2) {- return o1.getDate().compareTo(o2.getDate());- }-- });- }-- return comments;- }-- };+ private final IModel<Map<Integer, List<InlineComment>>> commentsModel;++ private WebMarkupContainer head;++ private ListView<DiffHunk> hunksView;private RepeatingView commentsView;+ private AbstractDefaultAjaxBehavior addCommentBehavior;+private String autoScrollScript;- private void onDiffOptionChanged() {- if (diffOption == DiffOption.IGNORE_EOL) {- effectiveOldText = oldText.ignoreEOL();- effectiveNewText = newText.ignoreEOL();- } else if (diffOption == DiffOption.IGNORE_EOL_SPACES) {- effectiveOldText = oldText.ignoreEOLSpaces();- effectiveNewText = newText.ignoreEOLSpaces();- } else if (diffOption == DiffOption.IGNORE_CHANGE_SPACES) {- effectiveOldText = oldText.ignoreChangeSpaces();- effectiveNewText = newText.ignoreChangeSpaces();- } else {- effectiveOldText = oldText;- effectiveNewText = newText;- }-- diffs = DiffUtils.diff(effectiveOldText.getLines(), effectiveNewText.getLines(), new WordSplitter());- }-- private boolean isIdentical() {- for (DiffLine diffLine: diffs) {- if (diffLine.getAction() != EQUAL)- return false;- }- return true;- }-public TextDiffPanel(String id, final IModel<Repository> repoModel,BlobText oldText, BlobText newText, RevAwareChange change,- @Nullable InlineCommentSupport commentContext) {+ final @Nullable InlineCommentSupport commentSupport) {super(id);this.repoModel = repoModel;-Preconditions.checkArgument(!change.getOldRevision().equals(change.getNewRevision()));this.change = change;- this.commentSupport = commentContext;+ this.commentSupport = commentSupport;this.oldText = oldText;this.newText = newText;@@ -209,16 +146,109 @@ public class TextDiffPanel extends Panel implements InlineContextAware {};+ commentsModel = new LoadableDetachableModel<Map<Integer, List<InlineComment>>>() {++ @Override+ protected Map<Integer, List<InlineComment>> load() {+ Preconditions.checkNotNull(commentSupport);++ Map<Integer, Integer> oldLinesMap = new HashMap<>();+ Map<Integer, Integer> newLinesMap = new HashMap<>();++ int index = 0;+ for (DiffLine diff: diffs) {+ oldLinesMap.put(diff.getOldLineNo(), index);+ newLinesMap.put(diff.getNewLineNo(), index);+ index++;+ }++ Map<Integer, List<InlineComment>> comments = new HashMap<>();+ for (Map.Entry<Integer, List<InlineComment>> entry: commentSupport.getOldComments().entrySet()) {+ int diffLineNo = oldLinesMap.get(entry.getKey());+ List<InlineComment> lineComments = comments.get(diffLineNo);+ if (lineComments == null) {+ lineComments = new ArrayList<>();+ comments.put(diffLineNo, lineComments);+ }+ lineComments.addAll(entry.getValue());+ }+ for (Map.Entry<Integer, List<InlineComment>> entry: commentSupport.getNewComments().entrySet()) {+ int diffLineNo = newLinesMap.get(entry.getKey());+ List<InlineComment> lineComments = comments.get(diffLineNo);+ if (lineComments == null) {+ lineComments = new ArrayList<>();+ comments.put(diffLineNo, lineComments);+ }+ lineComments.addAll(entry.getValue());+ }++ for (List<InlineComment> lineComments: comments.values()) {+ Collections.sort(lineComments, new Comparator<InlineComment>() {++ @Override+ public int compare(InlineComment o1, InlineComment o2) {+ return o1.getDate().compareTo(o2.getDate());+ }++ });+ }++ return comments;+ }++ };+onDiffOptionChanged();}++ private void onDiffOptionChanged() {+ if (diffOption == DiffOption.IGNORE_EOL) {+ effectiveOldText = oldText.ignoreEOL();+ effectiveNewText = newText.ignoreEOL();+ } else if (diffOption == DiffOption.IGNORE_EOL_SPACES) {+ effectiveOldText = oldText.ignoreEOLSpaces();+ effectiveNewText = newText.ignoreEOLSpaces();+ } else if (diffOption == DiffOption.IGNORE_CHANGE_SPACES) {+ effectiveOldText = oldText.ignoreChangeSpaces();+ effectiveNewText = newText.ignoreChangeSpaces();+ } else {+ effectiveOldText = oldText;+ effectiveNewText = newText;+ }++ diffs = DiffUtils.diff(effectiveOldText.getLines(), effectiveNewText.getLines(), new WordSplitter());++ identical = true;+ for (DiffLine diffLine: diffs) {+ if (diffLine.getAction() != EQUAL) {+ identical = false;+ break;+ }+ }++ if (commentSupport != null) {+ hunks = DiffUtils.hunksOf(diffs, commentSupport.getOldComments().keySet(),+ commentSupport.getNewComments().keySet(), CONTEXT_SIZE);+ } else {+ hunks = DiffUtils.hunksOf(diffs, CONTEXT_SIZE);+ }+ }+ private boolean isDisplayingFull() {+ int lines = 0;+ for (DiffHunk hunk: hunks)+ lines += hunk.getDiffLines().size();++ return lines == diffs.size();+ }+@Overrideprotected void onInitialize() {super.onInitialize();setOutputMarkupId(true);- final WebMarkupContainer head = new WebMarkupContainer(HEAD_ID);+ head = new WebMarkupContainer("head");head.add(new StickyBehavior());@@ -234,7 +264,7 @@ public class TextDiffPanel extends Panel implements InlineContextAware {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible(!isIdentical());+ setVisible(!identical);}});@@ -255,59 +285,46 @@ public class TextDiffPanel extends Panel implements InlineContextAware {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible(isIdentical());+ setVisible(identical);}});- head.add(new WebMarkupContainer("prevDiff") {+ WebMarkupContainer diffNavs = new WebMarkupContainer("diffNavs") {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible(!isIdentical());+ setVisible(!identical && isDisplayingFull());}- }.add(new ScrollBehavior(".diff-block", SCROLL_MARGIN, false)));-- head.add(new WebMarkupContainer("nextDiff") {-- @Override- protected void onConfigure() {- super.onConfigure();- setVisible(!isIdentical());- }-- }.add(new ScrollBehavior(".diff-block", SCROLL_MARGIN, true)));+ };+ head.add(diffNavs);- // add a separate comment actions container in order not to refresh the whole- // sticky head when show/hide comment actions (refreshing sticky head via Wicket- // ajax has some displaying issues)- WebMarkupContainer commentActions = new WebMarkupContainer(COMMENT_ACTIONS_ID);- commentActions.setOutputMarkupId(true);+ diffNavs.add(new WebMarkupContainer("prevDiff").add(new ScrollBehavior(".diff-block", SCROLL_MARGIN, false)));+ diffNavs.add(new WebMarkupContainer("nextDiff").add(new ScrollBehavior(".diff-block", SCROLL_MARGIN, true)));- head.add(commentActions);- commentActions.add(new WebMarkupContainer("prevComment") {+ head.add(new WebMarkupContainer("prevComment") {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible(commentSupport != null && showComments);+ setVisible(commentSupport != null && showComments && isDisplayingFull());}}.add(new ScrollBehavior(".comments.line", 50, false)));- commentActions.add(new WebMarkupContainer("nextComment") {+ head.add(new WebMarkupContainer("nextComment") {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible(commentSupport != null && showComments);+ setVisible(commentSupport != null && showComments && isDisplayingFull());}}.add(new ScrollBehavior(".comments.line", 50, true)));- commentActions.add(new AjaxLink<Void>("showComments") {+ head.add(new AjaxLink<Void>("showComments") {@Overridepublic void onClick(AjaxRequestTarget target) {@@ -321,7 +338,7 @@ public class TextDiffPanel extends Panel implements InlineContextAware {}});- commentActions.add(new AjaxLink<Void>("hideComments") {+ head.add(new AjaxLink<Void>("hideComments") {@Overridepublic void onClick(AjaxRequestTarget target) {@@ -335,6 +352,24 @@ public class TextDiffPanel extends Panel implements InlineContextAware {}});++ head.add(new AjaxLink<Void>("displayFull") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ hunks = new ArrayList<>();+ hunks.add(new DiffHunk(0, 0, diffs));+ target.add(TextDiffPanel.this);+ }++ @Override+ protected void onConfigure() {+ super.onConfigure();++ setVisible(!isDisplayingFull());+ }++ });MenuPanel diffOptionMenuPanel = new MenuPanel("diffOptions") {@@ -524,13 +559,11 @@ public class TextDiffPanel extends Panel implements InlineContextAware {});add(form);- final AbstractDefaultAjaxBehavior addCommentBehavior;add(addCommentBehavior = new AbstractDefaultAjaxBehavior() {@Overrideprotected void updateAjaxAttributes(AjaxRequestAttributes attributes) {super.updateAjaxAttributes(attributes);-attributes.getDynamicExtraParameters().add("return {index: index}");}@@ -551,74 +584,205 @@ public class TextDiffPanel extends Panel implements InlineContextAware {});- add(new Label("diffs", new LoadableDetachableModel<String>() {+ add(hunksView = new ListView<DiffHunk>("hunks", new AbstractReadOnlyModel<List<DiffHunk>>() {@Override- protected String load() {- StringBuilder builder = new StringBuilder("<table id='diffs-table' class='table-diff'>");- int index = 0;- for (DiffLine diff: diffs) {- String addCommentLink;- if (allowToAddCommentModel.getObject() && commentSupport != null) {- addCommentLink = "<a href='javascript: var index=" + index + "; "- + addCommentBehavior.getCallbackScript()- + ";' class='add-comment'><i class='fa fa-comment-add'></i></a>";- } else {- addCommentLink = "";- }- builder.append("<tr id='diffline-").append(index).append("' class='line content ");- if (diff.getAction() == ADD) {- if (index == 0 || diffs.get(index-1).getAction() == EQUAL)- builder.append("new diff-block'>");- else- builder.append("new'>");- builder.append("<td class='old line-no'>").append(addCommentLink).append("</td>");- builder.append("<td class='new line-no'>");- builder.append("+ ").append(diff.getNewLineNo()+1).append("</td>");- } else if (diff.getAction() == DELETE) {- if (index == 0 || diffs.get(index-1).getAction() == EQUAL)- builder.append("old diff-block'>");- else- builder.append("old'>");- builder.append("<td class='old line-no'>").append(addCommentLink);- builder.append("- ").append(diff.getOldLineNo()+1).append("</td>");- builder.append("<td class='new line-no'></td>");- } else {- builder.append("equal'>");- builder.append("<td class='old line-no'>").append(addCommentLink)- .append(" ").append(diff.getOldLineNo()+1).append("</td>");- builder.append("<td class='new line-no'> ").append(diff.getNewLineNo()+1).append("</td>");+ public List<DiffHunk> getObject() {+ return hunks;+ }++ }) {++ @Override+ protected void populateItem(final ListItem<DiffHunk> item) {+ DiffHunk hunk = item.getModelObject();++ item.add(newHunkHead("head", item.getIndex()));+ item.add(new Label("body", renderDiffs(hunk.getDiffLines())).setEscapeModelStrings(false));+ }++ });++ final WebMarkupContainer lastRow = new WebMarkupContainer("lastRow") {++ @Override+ protected void onConfigure() {+ super.onConfigure();++ if (hunks.isEmpty()) {+ setVisible(false);+ } else {+ int lines = 0;+ for (DiffLine diffLine: diffs) {+ if (diffLine.getAction() != DiffLine.Action.DELETE)+ lines++;}- builder.append("<td class='text'>");+ DiffHunk hunk = hunks.get(hunks.size()-1);+ setVisible(hunk.getNewEnd() < lines);+ }+ }++ };+ lastRow.setOutputMarkupId(true);+ add(lastRow);+ lastRow.add(new AjaxLink<Void>("expand") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ expandBelow(target, hunks.size()-1, diffs.size());+ target.add(findPrevVisibleHunkHead(hunks.size()));+ target.add(lastRow);+ target.add(head);+ }++ }.add(new TooltipBehavior(Model.of("Show more lines"))));++ add(newCommentsView());++ autoScrollScript = String.format("pmease.commons.scroll.next('.concerned-comment', %d);", SCROLL_MARGIN);+ }++ private String renderDiffs(List<DiffLine> diffLines) {+ Preconditions.checkArgument(!diffLines.isEmpty());++ StringBuilder builder = new StringBuilder();++ DiffLine firstLine = diffLines.get(0);+ int index = 0;+ for (DiffLine diff: diffs) {+ if (diff.getOldLineNo() == firstLine.getOldLineNo() && diff.getNewLineNo() == firstLine.getNewLineNo())+ break;+ index++;+ }++ for (DiffLine line: diffLines) {+ String addCommentLink;+ if (allowToAddCommentModel.getObject() && commentSupport != null) {+ addCommentLink = "<a href='javascript: var index=" + index + "; "+ + addCommentBehavior.getCallbackScript()+ + ";' class='add-comment'><i class='fa fa-comment-add'></i></a>";+ } else {+ addCommentLink = "";+ }+ builder.append("<tr id='diffline-").append(index).append("' class='line diff ");+ if (line.getAction() == ADD) {+ if (index == 0 || diffs.get(index-1).getAction() == EQUAL)+ builder.append("new diff-block'>");+ else+ builder.append("new'>");+ builder.append("<td class='old line-no'>").append(addCommentLink).append("</td>");+ builder.append("<td class='new line-no'>");+ builder.append(line.getNewLineNo()+1).append("</td>");+ } else if (line.getAction() == DELETE) {+ if (index == 0 || diffs.get(index-1).getAction() == EQUAL)+ builder.append("old diff-block'>");+ else+ builder.append("old'>");+ builder.append("<td class='old line-no'>").append(addCommentLink);+ builder.append(line.getOldLineNo()+1).append("</td>");+ builder.append("<td class='new line-no'></td>");+ } else {+ builder.append("equal'>");+ builder.append("<td class='old line-no'>").append(addCommentLink)+ .append(" ").append(line.getOldLineNo()+1).append("</td>");+ builder.append("<td class='new line-no'> ").append(line.getNewLineNo()+1).append("</td>");+ }+ builder.append("<td class='text'>");+ if (line.getAction() == ADD)+ builder.append("+");+ else if (line.getAction() == DELETE)+ builder.append("-");+ else+ builder.append(" ");+ for (Partial partial: line.getPartials()) {+ if (partial.isEmphasized())+ builder.append("<span class='emphasize'>");+ else+ builder.append("<span>");+ if (partial.getContent().equals("\r"))+ builder.append(" ");+ else+ builder.append(Strings.escapeMarkup(partial.getContent(), false, false));+ builder.append("</span>");+ }+ builder.append("</td></tr>");+ index++;+ }+ return builder.toString();+ }++ private WebMarkupContainer newHunkHead(String id, final int index) {+ final DiffHunk hunk = hunks.get(index);+ final WebMarkupContainer hunkHead = new WebMarkupContainer(id) {++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(index == 0 || hunk.getNewStart() > hunks.get(index-1).getNewEnd());+ }++ };+ hunkHead.add(new AjaxLink<Void>("expand") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ if (index == 0) {+ expandAbove(target, index, 0);+ target.add(hunkHead);+ } else {+ int diffPos = locateDiffPos(hunk.getNewStart(), DiffLine.Action.DELETE);+ expandBelow(target, index-1, diffPos);- for (Partial partial: diff.getPartials()) {- if (partial.isEmphasized())- builder.append("<span class='emphasize'>");- else- builder.append("<span>");- if (partial.getContent().equals("\r"))- builder.append(" ");- else- builder.append(Strings.escapeMarkup(partial.getContent(), false, false));- builder.append("</span>");+ diffPos = locateDiffPos(hunks.get(index-1).getNewEnd(), DiffLine.Action.DELETE);+ expandAbove(target, index, diffPos);++ target.add(hunkHead);+ target.add(findPrevVisibleHunkHead(index));+ }+ target.add(head);+ }++ @Override+ protected void onConfigure() {+ super.onConfigure();++ if (index == 0) {+ setVisible(hunk.getOldStart() != 0 && hunk.getNewStart() != 0);+ } else {+ DiffHunk previousHunk = hunks.get(index-1);+ setVisible(previousHunk.getNewEnd() < hunk.getNewStart());+ }+ }++ }.add(new TooltipBehavior(Model.of("Show more lines"))));++ hunkHead.add(new Label("content", new AbstractReadOnlyModel<String>() {++ @Override+ public String getObject() {+ int oldStart = hunk.getOldStart();+ int newStart = hunk.getNewStart();+ int oldEnd = hunk.getOldEnd();+ int newEnd = hunk.getNewEnd();+ for (int i=index+1; i<hunks.size(); i++) {+ DiffHunk nextHunk = hunks.get(i);+ if (newEnd == nextHunk.getNewStart()) {+ newEnd = nextHunk.getNewEnd();+ oldEnd = nextHunk.getOldEnd();+ } else {+ break;}- builder.append("</td></tr>");- index++;}- return builder.append("</table>").toString();+ return DiffHunk.describe(oldStart, newStart, oldEnd, newEnd);}- }).setEscapeModelStrings(false));+ }));- add(newCommentsView());+ hunkHead.setOutputMarkupId(true);- autoScrollScript = String.format(""- + "if ($('.concerned-comment').length != 0) "- + " pmease.commons.scroll.next('.concerned-comment', %d);"- + "else"- + " pmease.commons.scroll.next('.diff-block:first', %d);", SCROLL_MARGIN * 2, SCROLL_MARGIN);+ return hunkHead;}-+private Component newCommentsRow(String id, final int index) {WebMarkupContainer row = new WebMarkupContainer(commentsView.newChildId()) {@@ -628,9 +792,9 @@ public class TextDiffPanel extends Panel implements InlineContextAware {if (event.getPayload() instanceof CommentRemoved) {CommentRemoved commentRemoved = (CommentRemoved) event.getPayload();+ commentsView.remove(this);commentsModel.getObject().get(index).remove(commentRemoved.getComment());- commentRemoved.getTarget().appendJavaScript(- String.format("$('#%s').closest('tr').remove();", getMarkupId()));+ commentRemoved.getTarget().appendJavaScript(String.format("gitplex.comments.afterRemove(%d);", index));}}@@ -680,14 +844,14 @@ public class TextDiffPanel extends Panel implements InlineContextAware {private void showComments(AjaxRequestTarget target) {showComments = true;- target.add(get(HEAD_ID).get(COMMENT_ACTIONS_ID));+ target.add(head);target.appendJavaScript("$('.comments.line').show();");}private void hideComments(AjaxRequestTarget target) {showComments = false;- target.add(get(HEAD_ID).get(COMMENT_ACTIONS_ID));+ target.add(head);target.appendJavaScript("$('.comments.line').hide();");}@@ -767,4 +931,67 @@ public class TextDiffPanel extends Panel implements InlineContextAware {return new InlineContext(contextDiffs, index-start, start>0, end<diffs.size()-1);}++ private int locateDiffPos(int lineNo, DiffLine.Action excludeAction) {+ int index = 0;+ for (int i=0; i<diffs.size(); i++) {+ if (index < lineNo) {+ if (diffs.get(i).getAction() != excludeAction)+ index++;+ } else {+ return i;+ }+ }+ throw new IllegalStateException();+ }++ private void expandBelow(AjaxRequestTarget target, int hunkIndex, int diffLimit) {+ DiffHunk hunk = hunks.get(hunkIndex);++ int diffPos = locateDiffPos(hunk.getNewEnd(), DiffLine.Action.DELETE);+ for (int i = diffPos; i<diffs.size(); i++) {+ if (i-diffPos < CONTEXT_SIZE*2 && i<diffLimit) {+ DiffLine line = diffs.get(i);+ hunk.getDiffLines().add(line);+ hunk.setNewEnd(hunk.getNewEnd()+1);+ hunk.setOldEnd(hunk.getOldEnd()+1);++ String row = renderDiffs(Lists.newArrayList(line));+ row = StringUtils.replace(row, "\"", "\\\"");+ String script = String.format("$(\"%s\").insertAfter('#diffline-%d')", row, i-1);+ target.appendJavaScript(script);+ } else {+ break;+ }+ }+ }++ private Component findPrevVisibleHunkHead(int index) {+ for (int i=index-1; i>=0; i--) {+ Component hunkHead = hunksView.get(i).get("head");+ hunkHead.configure();+ if (hunkHead.isVisible())+ return hunkHead;+ }+ throw new IllegalStateException();+ }++ private void expandAbove(AjaxRequestTarget target, int hunkIndex, int diffLimit) {+ DiffHunk hunk = hunks.get(hunkIndex);+ int diffPos = locateDiffPos(hunk.getNewStart(), DiffLine.Action.DELETE);+ for (int i=diffPos-1; i>=diffLimit; i--) {+ if (diffPos-i <= CONTEXT_SIZE*2) {+ hunk.setOldStart(hunk.getOldStart()-1);+ hunk.setNewStart(hunk.getNewStart()-1);+ DiffLine line = diffs.get(i);+ hunk.getDiffLines().add(0, line);+ String row = renderDiffs(Lists.newArrayList(line));+ row = StringUtils.replace(row, "\"", "\\\"");+ String script = String.format("$(\"%s\").insertBefore('#diffline-%d')", row, i+1);+ target.appendJavaScript(script);+ } else {+ break;+ }+ }+ }}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/CommentActivityPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/CommentActivityPanel.htmlindex d1a7672183..bfa150670a 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/CommentActivityPanel.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/CommentActivityPanel.html@@ -10,7 +10,6 @@<div class="panel-heading"><span wicket:id="file"></span><span class="actions">- <a wicket:id="displayFullContext" class="fa fa-file-txt" title="Display comment in full context"></a><a wicket:id="compareWithLatest" class="fa fa-diff" title="Display comment by comparing with latest commit"></a></span></div>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/CommentActivityPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/CommentActivityPanel.javaindex ad8332434c..a53ecb9050 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/CommentActivityPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/CommentActivityPanel.java@@ -39,9 +39,7 @@ public class CommentActivityPanel extends Panel {fragment.add(new Label("file", comment.getFile()));- PageParameters params = RequestComparePage.paramsOf(comment.getRequest(), null, null, null, comment);- fragment.add(new BookmarkablePageLink<>("displayFullContext", RequestComparePage.class, params));- params = RequestComparePage.paramsOf(comment.getRequest(), comment.getCommit(), null, null, comment);+ PageParameters params = RequestComparePage.paramsOf(comment.getRequest(), comment.getCommit(), null, null, comment);fragment.add(new BookmarkablePageLink<Void>("compareWithLatest", RequestComparePage.class, params));fragment.add(new InlineCommentPanel("comment", commentModel));diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/InlineCommentPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/InlineCommentPanel.htmlindex 984e915a4c..f989ddc1c2 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/InlineCommentPanel.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/InlineCommentPanel.html@@ -4,14 +4,14 @@<td colspan="3"><i class="fa fa-ellipsis"></i></td></tr><wicket:container wicket:id="lines">- <tr wicket:id="contentRow" class="line content">+ <tr wicket:id="contentRow" class="line diff"><td class="old line-no"><span wicket:id="oldLineNo"></span></td><td class="new line-no"><span wicket:id="newLineNo"></span></td>- <td class="text"><wicket:container wicket:id="partials"><span wicket:id="partial"></span></wicket:container></td>+ <td class="text"><wicket:container wicket:id="diffMark"></wicket:container><wicket:container wicket:id="partials"><span wicket:id="partial"></span></wicket:container></td></tr><wicket:enclosure child="comment"><tr class="line comments">diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/InlineCommentPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/InlineCommentPanel.javaindex 39f132e194..906d2d7c33 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/InlineCommentPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/InlineCommentPanel.java@@ -70,15 +70,18 @@ public class InlineCommentPanel extends Panel {if (diffLine.getAction() == ADD) {contentRow.add(AttributeAppender.append("class", " new"));contentRow.add(new Label("oldLineNo"));- contentRow.add(new Label("newLineNo", "+ " + (diffLine.getNewLineNo() + 1)));+ contentRow.add(new Label("newLineNo", diffLine.getNewLineNo() + 1));+ contentRow.add(new Label("diffMark", "+"));} else if (diffLine.getAction() == DELETE) {contentRow.add(AttributeAppender.append("class", " old"));- contentRow.add(new Label("oldLineNo", "- " + (diffLine.getOldLineNo() + 1)));+ contentRow.add(new Label("oldLineNo", diffLine.getOldLineNo() + 1));contentRow.add(new Label("newLineNo"));+ contentRow.add(new Label("diffMark", "-"));} else {contentRow.add(AttributeAppender.append("class", " equal"));- contentRow.add(new Label("oldLineNo", " " + (diffLine.getOldLineNo()+1)));- contentRow.add(new Label("newLineNo", " " + (diffLine.getNewLineNo()+1)));+ contentRow.add(new Label("oldLineNo", diffLine.getOldLineNo()+1));+ contentRow.add(new Label("newLineNo", diffLine.getNewLineNo()+1));+ contentRow.add(new Label("diffMark", " "));}contentRow.add(new ListView<Partial>("partials", diffLine.getPartials()) {