提交 c25b7499 编写于 作者: M Matt Bierner

Strict null checking inputbox

上级 a626cc19
......@@ -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",
......
......@@ -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
......
......@@ -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<string>());
public readonly onDidChange: Event<string> = 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();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册