From fc86ba359f407c7140eb563df804cc05ab842f4e Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Thu, 7 Jun 2018 15:35:16 +0200 Subject: [PATCH] #50583 Implement Input box with history --- src/vs/base/browser/ui/inputbox/inputBox.ts | 51 ++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/vs/base/browser/ui/inputbox/inputBox.ts b/src/vs/base/browser/ui/inputbox/inputBox.ts index 793fee96a71..c80a9de7f6c 100644 --- a/src/vs/base/browser/ui/inputbox/inputBox.ts +++ b/src/vs/base/browser/ui/inputbox/inputBox.ts @@ -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; + + constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, options: IHistoryInputOptions) { + super(container, contextViewProvider, options); + this.history = new HistoryNavigator(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(); + } } \ No newline at end of file