# HG changeset patch # User jlahoda # Date 1492706438 -7200 # Node ID 73cb7afafdff78b967cb03c7fd547fb5f46391c7 # Parent f113ce12fe24fbd24acf02711372d9f1e1c12426 8178821: jshell tool: ctrl-down does nothing in current context Summary: In MemoryHistory index() of an entry may go beyond size() (if some leading entries have been deleted) - using previous()/next() instead. Reviewed-by: rfield diff -r f113ce12fe24 -r 73cb7afafdff jdk/src/jdk.internal.le/share/classes/jdk/internal/jline/extra/EditingHistory.java --- a/jdk/src/jdk.internal.le/share/classes/jdk/internal/jline/extra/EditingHistory.java Wed Jul 05 23:13:48 2017 +0200 +++ b/jdk/src/jdk.internal.le/share/classes/jdk/internal/jline/extra/EditingHistory.java Thu Apr 20 18:40:38 2017 +0200 @@ -264,9 +264,8 @@ } public boolean previousSnippet() { - for (int i = index() - 1; i >= 0; i--) { - if (get(i) instanceof NarrowingHistoryLine) { - moveTo(i); + while (previous()) { + if (current() instanceof NarrowingHistoryLine) { return true; } } @@ -275,19 +274,17 @@ } public boolean nextSnippet() { - for (int i = index() + 1; i < size(); i++) { - if (get(i) instanceof NarrowingHistoryLine) { - moveTo(i); + boolean success = false; + + while (next()) { + success = true; + + if (current() instanceof NarrowingHistoryLine) { return true; } } - if (index() < size()) { - moveToEnd(); - return true; - } - - return false; + return success; } public final void load(Iterable originalHistory) { diff -r f113ce12fe24 -r 73cb7afafdff jdk/test/jdk/internal/jline/extra/HistoryTest.java --- a/jdk/test/jdk/internal/jline/extra/HistoryTest.java Wed Jul 05 23:13:48 2017 +0200 +++ b/jdk/test/jdk/internal/jline/extra/HistoryTest.java Thu Apr 20 18:40:38 2017 +0200 @@ -23,6 +23,7 @@ /* * @test + * @bug 8178821 * @summary Test Completion * @modules jdk.internal.le/jdk.internal.jline * jdk.internal.le/jdk.internal.jline.console @@ -152,6 +153,15 @@ complete.set(true); history.add("}"); previousSnippetAndAssert(history, "void test() { /*after full*/"); + nextSnippetAndAssert(history, ""); + + assertFalse(history.nextSnippet()); + + while (history.previousSnippet()) + ; + + while (history.nextSnippet()) + ; } private void previousAndAssert(EditingHistory history, String expected) {