未验证 提交 e97426ba 编写于 作者: I Isidor Nikolic 提交者: GitHub

Merge pull request #93125 from piraces/fix-history-extra-navigations

Fix history entries navigation taking extra navigates in debug console
......@@ -28,11 +28,17 @@ export class HistoryNavigator<T> implements INavigator<T> {
}
public next(): T | null {
return this._navigator.next();
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 {
......@@ -73,6 +79,15 @@ export class HistoryNavigator<T> implements INavigator<T> {
}
}
private _currentPosition(): number {
const currentElement = this._navigator.current();
if (!currentElement) {
return -1;
}
return this._elements.indexOf(currentElement);
}
private _initialize(history: readonly T[]): void {
this._history = new Set();
for (const entry of history) {
......
......@@ -106,6 +106,40 @@ suite('History Navigator', () => {
assert.deepEqual(['2', '3', '1'], toArray(testObject));
});
test('previous returns null if the current position is the first one', () => {
const testObject = new HistoryNavigator(['1', '2', '3']);
testObject.first();
assert.deepEqual(testObject.previous(), null);
});
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.previous(), '1');
});
test('next returns null if the current position is the last one', () => {
const testObject = new HistoryNavigator(['1', '2', '3']);
testObject.last();
assert.deepEqual(testObject.next(), null);
});
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.next(), '3');
});
test('clear', () => {
const testObject = new HistoryNavigator(['a', 'b', 'c']);
assert.equal(testObject.previous(), 'c');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册