Commit 0bc37e5d authored by Skylot's avatar Skylot

gui: fix jump manager

parent 46c85728
......@@ -26,7 +26,7 @@ public class JumpManager {
}
private Position getCurrent() {
if (currentPos < list.size()) {
if (currentPos >= 0 && currentPos < list.size()) {
return list.get(currentPos);
}
return null;
......@@ -41,9 +41,14 @@ public class JumpManager {
}
public Position getNext() {
int size = list.size();
if (size == 0) {
currentPos = 0;
return null;
}
int newPos = currentPos + 1;
if (newPos >= list.size()) {
currentPos = list.size() - 1;
if (newPos >= size) {
currentPos = size - 1;
return null;
}
Position position = list.get(newPos);
......
......@@ -18,6 +18,15 @@ class TestJumpManager extends Specification {
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"() {
when:
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