#50583 Implement Input box with history

This commit is contained in:
Sandeep Somavarapu
2018-06-07 15:35:16 +02:00
parent 8950954a42
commit fc86ba359f

View File

@@ -18,6 +18,7 @@ import { Event, Emitter } from 'vs/base/common/event';
import { Widget } from 'vs/base/browser/ui/widget';
import { Color } from 'vs/base/common/color';
import { mixin } from 'vs/base/common/objects';
import { HistoryNavigator } from 'vs/base/common/history';
const $ = dom.$;
@@ -80,7 +81,7 @@ const defaultOpts = {
export class InputBox extends Widget {
private contextViewProvider: IContextViewProvider;
private element: HTMLElement;
element: HTMLElement;
private input: HTMLInputElement;
private mirror: HTMLElement;
private actionbar: ActionBar;
@@ -496,4 +497,52 @@ export class InputBox extends Widget {
super.dispose();
}
}
export interface IHistoryInputOptions extends IInputOptions {
history: string[];
}
export class HistoryInputBox extends InputBox {
private readonly history: HistoryNavigator<string>;
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, options: IHistoryInputOptions) {
super(container, contextViewProvider, options);
this.history = new HistoryNavigator<string>(options.history, 100);
}
public addToHistory(value: string): void {
if (value !== this.history.current()) {
this.history.add(value);
}
}
public getHistory(): string[] {
return this.history.getHistory();
}
public showNextValue() {
let next = this.history.next();
if (next) {
this.value = next;
}
}
public showPreviousValue() {
let previous;
if (this.value.length === 0) {
previous = this.history.current();
} else {
this.history.addIfNotPresent(this.value);
previous = this.history.previous();
}
if (previous) {
this.value = previous;
}
}
public clearHistory(): void {
this.history.clear();
}
}