Fix n/p on a file with only one edit

Back in 8724604fa9 ("Make n/p only honor comments on add/delete")
I tried to teach n/p keyboard shortcuts to jump to comments when
the change is the addition of a file, or the deletion of a file,
as the entire thing is one giant edit list.

Unfortunately this was based around just having 1 edit, and not
checking the *type* of the file change, so n/p broke when there
was exactly one region affected in the file.

We now only match comments if there is exactly one hunk and either
side of the patch script is empty (indicating full add or delete).

Bug: GERRIT-213
Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/src/main/java/com/google/gerrit/client/patches/AbstractPatchContentTable.java b/src/main/java/com/google/gerrit/client/patches/AbstractPatchContentTable.java
index 229f60f..ce620f1 100644
--- a/src/main/java/com/google/gerrit/client/patches/AbstractPatchContentTable.java
+++ b/src/main/java/com/google/gerrit/client/patches/AbstractPatchContentTable.java
@@ -26,6 +26,7 @@
 import com.google.gerrit.client.data.AccountInfoCache;
 import com.google.gerrit.client.data.PatchScript;
 import com.google.gerrit.client.data.PatchSetDetail;
+import com.google.gerrit.client.data.SparseFileContent;
 import com.google.gerrit.client.reviewdb.Change;
 import com.google.gerrit.client.reviewdb.Patch;
 import com.google.gerrit.client.reviewdb.PatchLineComment;
@@ -174,6 +175,16 @@
     return null;
   }
 
+  protected void initScript(final PatchScript script) {
+    if (script.getEdits().size() == 1) {
+      final SparseFileContent a = script.getA();
+      final SparseFileContent b = script.getB();
+      onlyOneHunk = a.size() == 0 || b.size() == 0;
+    } else {
+      onlyOneHunk = false;
+    }
+  }
+
   private boolean isChunk(final int row) {
     final Object o = getRowItem(row);
     if (!onlyOneHunk && o instanceof PatchLine) {
diff --git a/src/main/java/com/google/gerrit/client/patches/SideBySideTable.java b/src/main/java/com/google/gerrit/client/patches/SideBySideTable.java
index 1edf12a..9a77424 100644
--- a/src/main/java/com/google/gerrit/client/patches/SideBySideTable.java
+++ b/src/main/java/com/google/gerrit/client/patches/SideBySideTable.java
@@ -121,7 +121,7 @@
       appendSkipLine(nc, b.size() - lastB);
     }
     resetHtml(nc);
-    onlyOneHunk = script.getEdits().size() == 1;
+    initScript(script);
 
     for (int row = 0; row < lines.size(); row++) {
       setRowItem(row, lines.get(row));
diff --git a/src/main/java/com/google/gerrit/client/patches/UnifiedDiffTable.java b/src/main/java/com/google/gerrit/client/patches/UnifiedDiffTable.java
index 830f433..9fad61b 100644
--- a/src/main/java/com/google/gerrit/client/patches/UnifiedDiffTable.java
+++ b/src/main/java/com/google/gerrit/client/patches/UnifiedDiffTable.java
@@ -119,7 +119,7 @@
       }
     }
     resetHtml(nc);
-    onlyOneHunk = script.getEdits().size() == 1;
+    initScript(script);
 
     int row = script.getPatchHeader().size();
     final CellFormatter fmt = table.getCellFormatter();