changeset 44701:73cb7afafdff

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
author jlahoda
date Thu, 20 Apr 2017 18:40:38 +0200
parents f113ce12fe24
children df9a5567603a
files jdk/src/jdk.internal.le/share/classes/jdk/internal/jline/extra/EditingHistory.java jdk/test/jdk/internal/jline/extra/HistoryTest.java
diffstat 2 files changed, 19 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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<? extends String> originalHistory) {
--- 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) {