提交 0bc37e5d 编写于 作者: S Skylot

gui: fix jump manager

上级 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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册