提交 07b89997 编写于 作者: P piraces

Change fix to avoid changing the API of the history

上级 37302d7c
......@@ -27,20 +27,18 @@ export class HistoryNavigator<T> implements INavigator<T> {
this._onChange();
}
public hasNext(): boolean {
return this._currentPosition() !== this._elements.length - 1;
}
public next(): T | null {
return this._navigator.next();
}
public hasPrevious(): boolean {
return this._currentPosition() !== 0;
if (this._currentPosition() !== this._elements.length - 1) {
return this._navigator.next();
}
return null;
}
public previous(): T | null {
return this._navigator.previous();
if (this._currentPosition() !== 0) {
return this._navigator.previous();
}
return null;
}
public current(): T | null {
......
......@@ -106,38 +106,38 @@ suite('History Navigator', () => {
assert.deepEqual(['2', '3', '1'], toArray(testObject));
});
test('hasPrevious returns false if the current position is the first one', () => {
test('previous returns null if the current position is the first one', () => {
const testObject = new HistoryNavigator(['1', '2', '3']);
testObject.first();
assert.deepEqual(testObject.hasPrevious(), false);
assert.deepEqual(testObject.previous(), null);
});
test('hasPrevious returns true if the current position is not the first one', () => {
test('previous returns object if the current position is not the first one', () => {
const testObject = new HistoryNavigator(['1', '2', '3']);
testObject.first();
testObject.next();
assert.deepEqual(testObject.hasPrevious(), true);
assert.deepEqual(testObject.previous(), '1');
});
test('hasNext returns false if the current position is the last one', () => {
test('next returns null if the current position is the last one', () => {
const testObject = new HistoryNavigator(['1', '2', '3']);
testObject.last();
assert.deepEqual(testObject.hasNext(), false);
assert.deepEqual(testObject.next(), null);
});
test('hasNext returns true if the current position is not the last one', () => {
test('next returns object if the current position is not the last one', () => {
const testObject = new HistoryNavigator(['1', '2', '3']);
testObject.last();
testObject.previous();
assert.deepEqual(testObject.hasNext(), true);
assert.deepEqual(testObject.next(), '3');
});
test('clear', () => {
......
......@@ -228,15 +228,11 @@ export class Repl extends ViewPane implements IHistoryNavigationWidget {
}
showPreviousValue(): void {
if (this.history.hasPrevious()) {
this.navigateHistory(true);
}
this.navigateHistory(true);
}
showNextValue(): void {
if (this.history.hasNext()) {
this.navigateHistory(false);
}
this.navigateHistory(false);
}
focusRepl(): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册