Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable navigating past the end of history, to get an empty input box #179493

Merged
merged 2 commits into from Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/vs/base/browser/ui/inputbox/inputBox.ts
Expand Up @@ -711,10 +711,8 @@ export class HistoryInputBox extends InputBox implements IHistoryNavigationWidge
next = next === this.value ? this.getNextValue() : next;
}

if (next) {
this.value = next;
aria.status(this.value);
}
this.value = next ?? '';
aria.status(this.value ? this.value : nls.localize('clearedInput', "Cleared Input"));
}

public showPreviousValue(): void {
Expand Down Expand Up @@ -761,6 +759,6 @@ export class HistoryInputBox extends InputBox implements IHistoryNavigationWidge
}

private getNextValue(): string | null {
return this.history.next() || this.history.last();
return this.history.next();
}
}
8 changes: 3 additions & 5 deletions src/vs/base/common/history.ts
Expand Up @@ -28,10 +28,8 @@ export class HistoryNavigator<T> implements INavigator<T> {
}

public next(): T | null {
if (this._currentPosition() !== this._elements.length - 1) {
return this._navigator.next();
}
return null;
// This will navigate past the end of the last element, and in that case the input should be cleared
return this._navigator.next();
}

public previous(): T | null {
Expand All @@ -58,7 +56,7 @@ export class HistoryNavigator<T> implements INavigator<T> {
}

public isLast(): boolean {
return this._currentPosition() === this._elements.length - 1;
return this._currentPosition() >= this._elements.length - 1;
}

public isNowhere(): boolean {
Expand Down
8 changes: 5 additions & 3 deletions src/vs/base/test/common/history.test.ts
Expand Up @@ -72,7 +72,7 @@ suite('History Navigator', () => {
assert.strictEqual(testObject.isLast(), true);
assert.strictEqual(testObject.current(), '4');
assert.strictEqual(testObject.next(), null);
assert.strictEqual(testObject.isLast(), true);
assert.strictEqual(testObject.isLast(), false); // Stepping past the last element, is no longer "last"
});

test('previous on first element returns null and remains on first', () => {
Expand Down Expand Up @@ -109,8 +109,9 @@ suite('History Navigator', () => {
testObject.add('5');

assert.strictEqual(testObject.previous(), '5');
assert.strictEqual(testObject.next(), null);
assert.strictEqual(testObject.isLast(), true);
assert.strictEqual(testObject.next(), null);
assert.strictEqual(testObject.isLast(), false);
});

test('adding an existing item changes the order', () => {
Expand Down Expand Up @@ -144,8 +145,9 @@ suite('History Navigator', () => {

testObject.last();

assert.deepStrictEqual(testObject.next(), null);
assert.strictEqual(testObject.isLast(), true);
assert.deepStrictEqual(testObject.next(), null);
assert.strictEqual(testObject.isLast(), false);
});

test('next returns object if the current position is not the last one', () => {
Expand Down
Expand Up @@ -388,9 +388,7 @@ export class SuggestEnabledInputWithHistory extends SuggestEnabledInput implemen
next = next === this.getValue() ? this.getNextValue() : next;
}

if (next) {
this.setValue(next);
}
this.setValue(next ?? '');
}

public showPreviousValue(): void {
Expand Down Expand Up @@ -427,7 +425,7 @@ export class SuggestEnabledInputWithHistory extends SuggestEnabledInput implemen
}

private getNextValue(): string | null {
return this.history.next() || this.history.last();
return this.history.next();
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/vs/workbench/contrib/debug/browser/repl.ts
Expand Up @@ -384,14 +384,14 @@ export class Repl extends FilterViewPane implements IHistoryNavigationWidget {
}

private navigateHistory(previous: boolean): void {
const historyInput = previous ? this.history.previous() : this.history.next();
if (historyInput) {
this.replInput.setValue(historyInput);
aria.status(historyInput);
// always leave cursor at the end.
this.replInput.setPosition({ lineNumber: 1, column: historyInput.length + 1 });
this.setHistoryNavigationEnablement(true);
}
const historyInput = (previous ?
(this.history.previous() ?? this.history.first()) : this.history.next())
?? '';
this.replInput.setValue(historyInput);
aria.status(historyInput);
// always leave cursor at the end.
this.replInput.setPosition({ lineNumber: 1, column: historyInput.length + 1 });
this.setHistoryNavigationEnablement(true);
}

async selectSession(session?: IDebugSession): Promise<void> {
Expand Down
Expand Up @@ -98,17 +98,17 @@ export class InteractiveSessionInputPart extends Disposable implements IHistoryN
}

private navigateHistory(previous: boolean): void {
const historyInput = previous ? this.history.previous() : this.history.next();
const historyInput = (previous ?
(this.history.previous() ?? this.history.first()) : this.history.next())
?? '';

this.inputEditor.setValue(historyInput);
aria.status(historyInput);
if (historyInput) {
this.inputEditor.setValue(historyInput);
aria.status(historyInput);
if (historyInput) {
// always leave cursor at the end.
this.inputEditor.setPosition({ lineNumber: 1, column: historyInput.length + 1 });
}
this.setHistoryNavigationEnablement(true);
// always leave cursor at the end.
this.inputEditor.setPosition({ lineNumber: 1, column: historyInput.length + 1 });
}
this.setHistoryNavigationEnablement(true);
}

focus() {
Expand Down