diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/AbstractPatchContentTable.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/AbstractPatchContentTable.java index e91dbc5779..719414a908 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/AbstractPatchContentTable.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/AbstractPatchContentTable.java @@ -68,6 +68,8 @@ public abstract class AbstractPatchContentTable extends NavigationTable keysNavigation.add(new NextKeyCommand(0, 'j', PatchUtil.C.lineNext())); keysNavigation.add(new PrevChunkKeyCmd(0, 'p', PatchUtil.C.chunkPrev())); keysNavigation.add(new NextChunkKeyCmd(0, 'n', PatchUtil.C.chunkNext())); + keysNavigation.add(new PrevCommentCmd(0, 'P', PatchUtil.C.commentPrev())); + keysNavigation.add(new NextCommentCmd(0, 'N', PatchUtil.C.commentNext())); keysAction.add(new OpenKeyCommand(0, 'o', PatchUtil.C.expandComment())); keysAction.add(new OpenKeyCommand(0, KeyCodes.KEY_ENTER, PatchUtil.C @@ -258,6 +260,55 @@ public abstract class AbstractPatchContentTable extends NavigationTable } } + private void moveToPrevComment(int row) { + while (0 <= row && isComment(row)) { + row--; + } + for (; 0 <= row; row--) { + if (isComment(row)) { + movePointerTo(row, false); + scrollIntoView(oneBefore(row), oneAfter(row)); + return; + } + } + + // No prior comment found? Try to hit the first line in the file. + // + for (row = 0; row < table.getRowCount(); row++) { + if (getRowItem(row) != null) { + movePointerTo(row); + break; + } + } + } + + private void moveToNextComment(int row) { + final int max = table.getRowCount(); + while (row < max && isComment(row)) { + row++; + } + for (; row < max; row++) { + if (isComment(row)) { + movePointerTo(row, false); + scrollIntoView(oneBefore(row), oneAfter(row)); + return; + } + } + + // No next comment found? Try to hit the last line in the file. + // + for (row = max - 1; row >= 0; row--) { + if (getRowItem(row) != null) { + movePointerTo(row); + break; + } + } + } + + private boolean isComment(int row) { + return getRowItem(row) instanceof CommentList; + } + /** Invoked when the user clicks on a table cell. */ protected abstract void onCellDoubleClick(int row, int column); @@ -613,6 +664,30 @@ public abstract class AbstractPatchContentTable extends NavigationTable } } + public class PrevCommentCmd extends KeyCommand { + public PrevCommentCmd(int mask, int key, String help) { + super(mask, key, help); + } + + @Override + public void onKeyPress(final KeyPressEvent event) { + ensurePointerVisible(); + moveToPrevComment(getCurrentRow()); + } + } + + public class NextCommentCmd extends KeyCommand { + public NextCommentCmd(int mask, int key, String help) { + super(mask, key, help); + } + + @Override + public void onKeyPress(final KeyPressEvent event) { + ensurePointerVisible(); + moveToNextComment(getCurrentRow()); + } + } + private class PublishedCommentPanel extends CommentPanel implements ClickHandler { final PatchLineComment comment; diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchConstants.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchConstants.java index 652776d76c..495a149395 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchConstants.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchConstants.java @@ -39,6 +39,8 @@ public interface PatchConstants extends Constants { String lineNext(); String chunkPrev(); String chunkNext(); + String commentPrev(); + String commentNext(); String fileList(); String expandComment(); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchConstants.properties b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchConstants.properties index a4ff9304d6..c7bcf0a332 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchConstants.properties +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchConstants.properties @@ -20,6 +20,8 @@ linePrev = Previous line lineNext = Next line chunkPrev = Previous diff chunk or comment chunkNext = Next diff chunk or comment +commentPrev = Previous comment +commentNext = Next comment fileList = Browse files in patch set expandComment = Expand or collapse comment