Commit 0bc37e5d authored by Skylot's avatar Skylot

gui: fix jump manager

parent 46c85728
...@@ -26,7 +26,7 @@ public class JumpManager { ...@@ -26,7 +26,7 @@ public class JumpManager {
} }
private Position getCurrent() { private Position getCurrent() {
if (currentPos < list.size()) { if (currentPos >= 0 && currentPos < list.size()) {
return list.get(currentPos); return list.get(currentPos);
} }
return null; return null;
...@@ -41,9 +41,14 @@ public class JumpManager { ...@@ -41,9 +41,14 @@ public class JumpManager {
} }
public Position getNext() { public Position getNext() {
int size = list.size();
if (size == 0) {
currentPos = 0;
return null;
}
int newPos = currentPos + 1; int newPos = currentPos + 1;
if (newPos >= list.size()) { if (newPos >= size) {
currentPos = list.size() - 1; currentPos = size - 1;
return null; return null;
} }
Position position = list.get(newPos); Position position = list.get(newPos);
......
...@@ -18,6 +18,15 @@ class TestJumpManager extends Specification { ...@@ -18,6 +18,15 @@ class TestJumpManager extends Specification {
jm.getNext() == null jm.getNext() == null
} }
def "empty history 2"() {
expect:
jm.getPrev() == null
jm.getNext() == null
jm.getPrev() == null
jm.getNext() == null
jm.getPrev() == null
}
def "1 element"() { def "1 element"() {
when: when:
jm.addPosition(Mock(Position)) jm.addPosition(Mock(Position))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment