Use N/P to jump to next/previous comments
Previously "n" and "p" took you to the start of the next and previous code change hunk, or comment, whichever it encountered first in the file. Now "N" and "P" jump to the next comment, skipping over any code hunks which did not have comments on them. Bug: issue 380 Change-Id: I108c9764cd58001cee8eeb9f2d4cde4fc94d51c9 Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -68,6 +68,8 @@ public abstract class AbstractPatchContentTable extends NavigationTable<Object>
|
|||||||
keysNavigation.add(new NextKeyCommand(0, 'j', PatchUtil.C.lineNext()));
|
keysNavigation.add(new NextKeyCommand(0, 'j', PatchUtil.C.lineNext()));
|
||||||
keysNavigation.add(new PrevChunkKeyCmd(0, 'p', PatchUtil.C.chunkPrev()));
|
keysNavigation.add(new PrevChunkKeyCmd(0, 'p', PatchUtil.C.chunkPrev()));
|
||||||
keysNavigation.add(new NextChunkKeyCmd(0, 'n', PatchUtil.C.chunkNext()));
|
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, 'o', PatchUtil.C.expandComment()));
|
||||||
keysAction.add(new OpenKeyCommand(0, KeyCodes.KEY_ENTER, PatchUtil.C
|
keysAction.add(new OpenKeyCommand(0, KeyCodes.KEY_ENTER, PatchUtil.C
|
||||||
@@ -258,6 +260,55 @@ public abstract class AbstractPatchContentTable extends NavigationTable<Object>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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. */
|
/** Invoked when the user clicks on a table cell. */
|
||||||
protected abstract void onCellDoubleClick(int row, int column);
|
protected abstract void onCellDoubleClick(int row, int column);
|
||||||
|
|
||||||
@@ -613,6 +664,30 @@ public abstract class AbstractPatchContentTable extends NavigationTable<Object>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
private class PublishedCommentPanel extends CommentPanel implements
|
||||||
ClickHandler {
|
ClickHandler {
|
||||||
final PatchLineComment comment;
|
final PatchLineComment comment;
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ public interface PatchConstants extends Constants {
|
|||||||
String lineNext();
|
String lineNext();
|
||||||
String chunkPrev();
|
String chunkPrev();
|
||||||
String chunkNext();
|
String chunkNext();
|
||||||
|
String commentPrev();
|
||||||
|
String commentNext();
|
||||||
String fileList();
|
String fileList();
|
||||||
String expandComment();
|
String expandComment();
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ linePrev = Previous line
|
|||||||
lineNext = Next line
|
lineNext = Next line
|
||||||
chunkPrev = Previous diff chunk or comment
|
chunkPrev = Previous diff chunk or comment
|
||||||
chunkNext = Next diff chunk or comment
|
chunkNext = Next diff chunk or comment
|
||||||
|
commentPrev = Previous comment
|
||||||
|
commentNext = Next comment
|
||||||
fileList = Browse files in patch set
|
fileList = Browse files in patch set
|
||||||
expandComment = Expand or collapse comment
|
expandComment = Expand or collapse comment
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user