From c25b7499d18977e72e21234b581f09d9b076a6c0 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Fri, 7 Dec 2018 15:12:10 -0800 Subject: [PATCH] Strict null checking inputbox --- src/tsconfig.strictNullChecks.json | 1 + .../browser/ui/contextview/contextview.ts | 2 +- src/vs/base/browser/ui/inputbox/inputBox.ts | 68 ++++++++++--------- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/tsconfig.strictNullChecks.json b/src/tsconfig.strictNullChecks.json index 168f54c9358..4bce8607d06 100644 --- a/src/tsconfig.strictNullChecks.json +++ b/src/tsconfig.strictNullChecks.json @@ -36,6 +36,7 @@ "./vs/base/browser/ui/grid/gridview.ts", "./vs/base/browser/ui/highlightedlabel/highlightedLabel.ts", "./vs/base/browser/ui/iconLabel/iconLabel.ts", + "./vs/base/browser/ui/inputbox/inputBox.ts", "./vs/base/browser/ui/keybindingLabel/keybindingLabel.ts", "./vs/base/browser/ui/list/list.ts", "./vs/base/browser/ui/list/listPaging.ts", diff --git a/src/vs/base/browser/ui/contextview/contextview.ts b/src/vs/base/browser/ui/contextview/contextview.ts index 55384d0bbaa..97545edba8e 100644 --- a/src/vs/base/browser/ui/contextview/contextview.ts +++ b/src/vs/base/browser/ui/contextview/contextview.ts @@ -25,7 +25,7 @@ export const enum AnchorPosition { export interface IDelegate { getAnchor(): HTMLElement | IAnchor; - render(container: HTMLElement): IDisposable; + render(container: HTMLElement): IDisposable | null; focus?(): void; layout?(): void; anchorAlignment?: AnchorAlignment; // default: left diff --git a/src/vs/base/browser/ui/inputbox/inputBox.ts b/src/vs/base/browser/ui/inputbox/inputBox.ts index 1dccd462b1b..055e5bfb59d 100644 --- a/src/vs/base/browser/ui/inputbox/inputBox.ts +++ b/src/vs/base/browser/ui/inputbox/inputBox.ts @@ -83,32 +83,32 @@ const defaultOpts = { }; export class InputBox extends Widget { - private contextViewProvider: IContextViewProvider; + private contextViewProvider?: IContextViewProvider; element: HTMLElement; private input: HTMLInputElement; private mirror: HTMLElement; - private actionbar: ActionBar; + private actionbar?: ActionBar; private options: IInputOptions; - private message: IMessage; + private message: IMessage | null; private placeholder: string; private ariaLabel: string; - private validation: IInputValidator; - private state = 'idle'; - private cachedHeight: number; - - private inputBackground: Color; - private inputForeground: Color; - private inputBorder: Color; - - private inputValidationInfoBorder: Color; - private inputValidationInfoBackground: Color; - private inputValidationInfoForeground: Color; - private inputValidationWarningBorder: Color; - private inputValidationWarningBackground: Color; - private inputValidationWarningForeground: Color; - private inputValidationErrorBorder: Color; - private inputValidationErrorBackground: Color; - private inputValidationErrorForeground: Color; + private validation?: IInputValidator; + private state: string | null = 'idle'; + private cachedHeight: number | null; + + private inputBackground?: Color; + private inputForeground?: Color; + private inputBorder?: Color; + + private inputValidationInfoBorder?: Color; + private inputValidationInfoBackground?: Color; + private inputValidationInfoForeground?: Color; + private inputValidationWarningBorder?: Color; + private inputValidationWarningBackground?: Color; + private inputValidationWarningForeground?: Color; + private inputValidationErrorBorder?: Color; + private inputValidationErrorBackground?: Color; + private inputValidationErrorForeground?: Color; private _onDidChange = this._register(new Emitter()); public readonly onDidChange: Event = this._onDidChange.event; @@ -361,7 +361,7 @@ export class InputBox extends Widget { return !errorMsg; } - private stylesForType(type: MessageType): { border: Color; background: Color; foreground: Color } { + private stylesForType(type: MessageType | undefined): { border: Color | undefined; background: Color | undefined; foreground: Color | undefined } { switch (type) { case MessageType.INFO: return { border: this.inputValidationInfoBorder, background: this.inputValidationInfoBackground, foreground: this.inputValidationInfoForeground }; case MessageType.WARNING: return { border: this.inputValidationWarningBorder, background: this.inputValidationWarningBackground, foreground: this.inputValidationWarningForeground }; @@ -369,7 +369,7 @@ export class InputBox extends Widget { } } - private classForType(type: MessageType): string { + private classForType(type: MessageType | undefined): string { switch (type) { case MessageType.INFO: return 'info'; case MessageType.WARNING: return 'warning'; @@ -391,6 +391,10 @@ export class InputBox extends Widget { getAnchor: () => this.element, anchorAlignment: AnchorAlignment.RIGHT, render: (container: HTMLElement) => { + if (!this.message) { + return null; + } + div = dom.append(container, $('.monaco-inputbox-container')); layout(); @@ -433,7 +437,7 @@ export class InputBox extends Widget { this.validate(); this.updateMirror(); - if (this.state === 'open') { + if (this.state === 'open' && this.contextViewProvider) { this.contextViewProvider.layout(); } } @@ -509,15 +513,13 @@ export class InputBox extends Widget { public dispose(): void { this._hideMessage(); - this.element = null; - this.input = null; - this.contextViewProvider = null; + this.element = null!; // StrictNullOverride: nulling out ok in dispose + this.input = null!; // StrictNullOverride: nulling out ok in dispose + this.contextViewProvider = undefined; this.message = null; - this.placeholder = null; - this.ariaLabel = null; - this.validation = null; + this.validation = undefined; this.state = null; - this.actionbar = null; + this.actionbar = undefined; super.dispose(); } @@ -582,7 +584,7 @@ export class HistoryInputBox extends InputBox implements IHistoryNavigationWidge this.history.clear(); } - private getCurrentValue(): string { + private getCurrentValue(): string | null { let currentValue = this.history.current(); if (!currentValue) { currentValue = this.history.last(); @@ -591,11 +593,11 @@ export class HistoryInputBox extends InputBox implements IHistoryNavigationWidge return currentValue; } - private getPreviousValue(): string { + private getPreviousValue(): string | null { return this.history.previous() || this.history.first(); } - private getNextValue(): string { + private getNextValue(): string | null { return this.history.next() || this.history.last(); } } -- GitLab