diff options
author | Shawn O. Pearce <sop@google.com> | 2009-05-18 08:26:03 -0700 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2009-05-18 10:16:56 -0700 |
commit | 38134bf84c6cb4d3d699a5b24dd43dccde36a7c8 (patch) | |
tree | ab2dd19bde76d62316e3bc19ee9e24a99cf793f9 | |
parent | 47a82e4eae1c5158144ed9fc98ee225f7acf63a2 (diff) |
Ensure the row pointer is visible before moving it
If the user has manually scrolled the window by way of the scrollbar,
when they push j/k to move the pointer we should reposition it onto
the current viewport first, so the window stays roughly where the
user has positioned it.
Signed-off-by: Shawn O. Pearce <sop@google.com>
-rw-r--r-- | src/main/java/com/google/gerrit/client/patches/AbstractPatchContentTable.java | 3 | ||||
-rw-r--r-- | src/main/java/com/google/gerrit/client/ui/NavigationTable.java | 37 |
2 files changed, 40 insertions, 0 deletions
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 bdce4d22e1..1e051e075e 100644 --- a/src/main/java/com/google/gerrit/client/patches/AbstractPatchContentTable.java +++ b/src/main/java/com/google/gerrit/client/patches/AbstractPatchContentTable.java @@ -525,6 +525,7 @@ public abstract class AbstractPatchContentTable extends NavigationTable<Object> @Override public void onKeyPress(final KeyPressEvent event) { + ensurePointerVisible(); for (int row = getCurrentRow(); 0 <= row; row--) { final Object item = getRowItem(row); if (item instanceof PatchLine) { @@ -559,6 +560,7 @@ public abstract class AbstractPatchContentTable extends NavigationTable<Object> @Override public void onKeyPress(final KeyPressEvent event) { + ensurePointerVisible(); moveToPrevChunk(getCurrentRow()); } } @@ -570,6 +572,7 @@ public abstract class AbstractPatchContentTable extends NavigationTable<Object> @Override public void onKeyPress(final KeyPressEvent event) { + ensurePointerVisible(); moveToNextChunk(getCurrentRow()); } } diff --git a/src/main/java/com/google/gerrit/client/ui/NavigationTable.java b/src/main/java/com/google/gerrit/client/ui/NavigationTable.java index 343eb331ea..724e1c7e00 100644 --- a/src/main/java/com/google/gerrit/client/ui/NavigationTable.java +++ b/src/main/java/com/google/gerrit/client/ui/NavigationTable.java @@ -15,6 +15,7 @@ package com.google.gerrit.client.ui; import com.google.gerrit.client.Gerrit; +import com.google.gwt.dom.client.Document; import com.google.gwt.event.dom.client.KeyPressEvent; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.DOM; @@ -88,6 +89,39 @@ public abstract class NavigationTable<RowItem> extends FancyFlexTable<RowItem> { return currentRow; } + protected void ensurePointerVisible() { + final int max = table.getRowCount(); + int row = currentRow; + final int init = row; + if (row < 0) { + row = 0; + } else if (max <= row) { + row = max - 1; + } + + final CellFormatter fmt = table.getCellFormatter(); + final int sTop = Document.get().getScrollTop(); + final int sEnd = sTop + Document.get().getClientHeight(); + + while (0 <= row && row < max) { + final Element cur = DOM.getParent(fmt.getElement(row, C_ARROW)); + final int cTop = cur.getAbsoluteTop(); + final int cEnd = cTop + cur.getOffsetHeight(); + + if (cEnd < sTop) { + row++; + } else if (sEnd < cTop) { + row--; + } else if (getRowItem(row) != null) { + break; + } + } + + if (init != row) { + movePointerTo(row, false); + } + } + protected void movePointerTo(final int newRow) { movePointerTo(newRow, true); } @@ -186,6 +220,7 @@ public abstract class NavigationTable<RowItem> extends FancyFlexTable<RowItem> { @Override public void onKeyPress(final KeyPressEvent event) { + ensurePointerVisible(); onUp(); } } @@ -197,6 +232,7 @@ public abstract class NavigationTable<RowItem> extends FancyFlexTable<RowItem> { @Override public void onKeyPress(final KeyPressEvent event) { + ensurePointerVisible(); onDown(); } } @@ -208,6 +244,7 @@ public abstract class NavigationTable<RowItem> extends FancyFlexTable<RowItem> { @Override public void onKeyPress(final KeyPressEvent event) { + ensurePointerVisible(); onOpen(); } } |