< prev index next >

webrev/src/main/java/org/openjdk/skara/webrev/HunkCoalescer.java

Print this page
*** 238,10 ***
--- 238,13 ---
      }
  
      private Context createContextAfterHunk(Hunk hunk, Hunk nextNonEmptySourceHunk, Hunk nextNonEmptyTargetHunk) {
          var sourceAfterContextStart = hunk.source().range().end();
          var sourceAfterContextEnd = hunk.source().range().end() + numContextLines;
+         if (nextNonEmptySourceHunk != null || nextNonEmptyTargetHunk != null) {
+             sourceAfterContextEnd += numContextLines; // include the "before" context for the next hunk
+         }
          sourceAfterContextEnd = Math.min(sourceAfterContextEnd, sourceContent.size() + 1);
          if (nextNonEmptySourceHunk != null) {
              var nextNonEmptySourceHunkStart = nextNonEmptySourceHunk.source().range().start();
              sourceAfterContextEnd = sourceAfterContextEnd > nextNonEmptySourceHunkStart
                      ? Math.min(sourceAfterContextEnd, nextNonEmptySourceHunkStart)

*** 249,23 ***
          }
          var sourceAfterContextCount = sourceAfterContextEnd - sourceAfterContextStart;
  
          var destAfterContextStart = hunk.target().range().end();
          var destAfterContextEnd = hunk.target().range().end() + numContextLines;
          destAfterContextEnd = Math.min(destAfterContextEnd, destContent.size() + 1);
          if (nextNonEmptyTargetHunk != null) {
              var nextNonEmptyTargetHunkStart = nextNonEmptyTargetHunk.target().range().start();
              destAfterContextEnd = destAfterContextEnd > nextNonEmptyTargetHunkStart
                      ? Math.min(destAfterContextEnd, nextNonEmptyTargetHunkStart)
- 
-         if (nextNonEmptySourceHunk != null || nextNonEmptyTargetHunk != null) {
-             sourceAfterContextEnd += numContextLines;
-             destAfterContextEnd += numContextLines;
-         }
- 
          var destAfterContextCount = destAfterContextEnd - destAfterContextStart;
  
          var afterContextCount = Math.min(sourceAfterContextCount, destAfterContextCount);
  
          var sourceLineNumStart = hunk.source().lines().isEmpty() && hunk.source().range().start() == 0 ?
--- 252,20 ---
          }
          var sourceAfterContextCount = sourceAfterContextEnd - sourceAfterContextStart;
  
          var destAfterContextStart = hunk.target().range().end();
          var destAfterContextEnd = hunk.target().range().end() + numContextLines;
+         if (nextNonEmptySourceHunk != null || nextNonEmptyTargetHunk != null) {
+             destAfterContextEnd += numContextLines; // include the "before" context for the next hunk
+         }
          destAfterContextEnd = Math.min(destAfterContextEnd, destContent.size() + 1);
          if (nextNonEmptyTargetHunk != null) {
              var nextNonEmptyTargetHunkStart = nextNonEmptyTargetHunk.target().range().start();
              destAfterContextEnd = destAfterContextEnd > nextNonEmptyTargetHunkStart
                      ? Math.min(destAfterContextEnd, nextNonEmptyTargetHunkStart)
          var destAfterContextCount = destAfterContextEnd - destAfterContextStart;
  
          var afterContextCount = Math.min(sourceAfterContextCount, destAfterContextCount);
  
          var sourceLineNumStart = hunk.source().lines().isEmpty() && hunk.source().range().start() == 0 ?
< prev index next >