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

Strict null checking findWidget

上级 15413532
......@@ -295,6 +295,7 @@
"./vs/editor/contrib/find/findModel.ts",
"./vs/editor/contrib/find/findOptionsWidget.ts",
"./vs/editor/contrib/find/findState.ts",
"./vs/editor/contrib/find/findWidget.ts",
"./vs/editor/contrib/find/replaceAllCommand.ts",
"./vs/editor/contrib/find/replacePattern.ts",
"./vs/editor/contrib/folding/folding.ts",
......@@ -505,6 +506,7 @@
"./vs/platform/statusbar/common/statusbar.ts",
"./vs/platform/storage/common/storage.ts",
"./vs/platform/storage/node/storageMainService.ts",
"./vs/platform/storage/node/storageService.ts",
"./vs/platform/telemetry/browser/errorTelemetry.ts",
"./vs/platform/telemetry/common/telemetry.ts",
"./vs/platform/telemetry/common/telemetryService.ts",
......@@ -746,4 +748,4 @@
"exclude": [
"./typings/require-monaco.d.ts"
]
}
}
\ No newline at end of file
......@@ -32,7 +32,7 @@ export interface IFindInputOptions extends IFindInputStyles {
}
export interface IFindInputStyles extends IInputBoxStyles {
inputActiveOptionBorder?: Color;
inputActiveOptionBorder?: Color | null;
}
const NLS_DEFAULT_LABEL = nls.localize('defaultLabel', "input");
......@@ -48,20 +48,20 @@ export class FindInput extends Widget {
private label: string;
private fixFocusOnOptionClickEnabled = true;
private inputActiveOptionBorder?: Color;
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 inputActiveOptionBorder?: Color | null;
private inputBackground?: Color | null;
private inputForeground?: Color | null;
private inputBorder?: Color | null;
private inputValidationInfoBorder?: Color | null;
private inputValidationInfoBackground?: Color | null;
private inputValidationInfoForeground?: Color | null;
private inputValidationWarningBorder?: Color | null;
private inputValidationWarningBackground?: Color | null;
private inputValidationWarningForeground?: Color | null;
private inputValidationErrorBorder?: Color | null;
private inputValidationErrorBackground?: Color | null;
private inputValidationErrorForeground?: Color | null;
private regex: RegexCheckbox;
private wholeWords: WholeWordsCheckbox;
......@@ -90,7 +90,7 @@ export class FindInput extends Widget {
private _onRegexKeyDown = this._register(new Emitter<IKeyboardEvent>());
public readonly onRegexKeyDown: Event<IKeyboardEvent> = this._onRegexKeyDown.event;
constructor(parent: HTMLElement, contextViewProvider: IContextViewProvider, private readonly _showOptionButtons: boolean, options: IFindInputOptions) {
constructor(parent: HTMLElement | null, contextViewProvider: IContextViewProvider, private readonly _showOptionButtons: boolean, options: IFindInputOptions) {
super();
this.contextViewProvider = contextViewProvider;
this.width = options.width || 100;
......@@ -115,7 +115,7 @@ export class FindInput extends Widget {
this.buildDomNode(options.appendCaseSensitiveLabel || '', options.appendWholeWordsLabel || '', options.appendRegexLabel || '', options.history || [], !!options.flexibleHeight);
if (Boolean(parent)) {
if (parent) {
parent.appendChild(this.domNode);
}
......@@ -202,7 +202,7 @@ export class FindInput extends Widget {
protected applyStyles(): void {
if (this.domNode) {
const checkBoxStyles: ICheckboxStyles = {
inputActiveOptionBorder: this.inputActiveOptionBorder,
inputActiveOptionBorder: this.inputActiveOptionBorder || undefined,
};
this.regex.style(checkBoxStyles);
this.wholeWords.style(checkBoxStyles);
......@@ -313,7 +313,7 @@ export class FindInput extends Widget {
this.regex = this._register(new RegexCheckbox({
appendTitle: appendRegexLabel,
isChecked: false,
inputActiveOptionBorder: this.inputActiveOptionBorder
inputActiveOptionBorder: this.inputActiveOptionBorder || undefined
}));
this._register(this.regex.onChange(viaKeyboard => {
this._onDidOptionChange.fire(viaKeyboard);
......@@ -330,7 +330,7 @@ export class FindInput extends Widget {
this.wholeWords = this._register(new WholeWordsCheckbox({
appendTitle: appendWholeWordsLabel,
isChecked: false,
inputActiveOptionBorder: this.inputActiveOptionBorder
inputActiveOptionBorder: this.inputActiveOptionBorder || undefined
}));
this._register(this.wholeWords.onChange(viaKeyboard => {
this._onDidOptionChange.fire(viaKeyboard);
......@@ -344,7 +344,7 @@ export class FindInput extends Widget {
this.caseSensitive = this._register(new CaseSensitiveCheckbox({
appendTitle: appendCaseSensitiveLabel,
isChecked: false,
inputActiveOptionBorder: this.inputActiveOptionBorder
inputActiveOptionBorder: this.inputActiveOptionBorder || undefined
}));
this._register(this.caseSensitive.onChange(viaKeyboard => {
this._onDidOptionChange.fire(viaKeyboard);
......
......@@ -32,22 +32,22 @@ export interface IInputOptions extends IInputBoxStyles {
}
export interface IInputBoxStyles {
readonly inputBackground?: Color;
readonly inputForeground?: Color;
readonly inputBorder?: Color;
readonly inputValidationInfoBorder?: Color;
readonly inputValidationInfoBackground?: Color;
readonly inputValidationInfoForeground?: Color;
readonly inputValidationWarningBorder?: Color;
readonly inputValidationWarningBackground?: Color;
readonly inputValidationWarningForeground?: Color;
readonly inputValidationErrorBorder?: Color;
readonly inputValidationErrorBackground?: Color;
readonly inputValidationErrorForeground?: Color;
readonly inputBackground?: Color | null;
readonly inputForeground?: Color | null;
readonly inputBorder?: Color | null;
readonly inputValidationInfoBorder?: Color | null;
readonly inputValidationInfoBackground?: Color | null;
readonly inputValidationInfoForeground?: Color | null;
readonly inputValidationWarningBorder?: Color | null;
readonly inputValidationWarningBackground?: Color | null;
readonly inputValidationWarningForeground?: Color | null;
readonly inputValidationErrorBorder?: Color | null;
readonly inputValidationErrorBackground?: Color | null;
readonly inputValidationErrorForeground?: Color | null;
}
export interface IInputValidator {
(value: string): IMessage;
(value: string): IMessage | null;
}
export interface IMessage {
......@@ -96,19 +96,19 @@ export class InputBox extends Widget {
private state: string | null = 'idle';
private cachedHeight: number | null;
private inputBackground?: Color;
private inputForeground?: Color;
private inputBorder?: Color;
private inputBackground?: Color | null;
private inputForeground?: Color | null;
private inputBorder?: Color | null;
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 inputValidationInfoBorder?: Color | null;
private inputValidationInfoBackground?: Color | null;
private inputValidationInfoForeground?: Color | null;
private inputValidationWarningBorder?: Color | null;
private inputValidationWarningBackground?: Color | null;
private inputValidationWarningForeground?: Color | null;
private inputValidationErrorBorder?: Color | null;
private inputValidationErrorBackground?: Color | null;
private inputValidationErrorForeground?: Color | null;
private _onDidChange = this._register(new Emitter<string>());
public readonly onDidChange: Event<string> = this._onDidChange.event;
......@@ -116,7 +116,7 @@ export class InputBox extends Widget {
private _onDidHeightChange = this._register(new Emitter<number>());
public readonly onDidHeightChange: Event<number> = this._onDidHeightChange.event;
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, options?: IInputOptions) {
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider | undefined, options?: IInputOptions) {
super();
this.contextViewProvider = contextViewProvider;
......@@ -361,7 +361,7 @@ export class InputBox extends Widget {
return !errorMsg;
}
private stylesForType(type: MessageType | undefined): { border: Color | undefined; background: Color | undefined; foreground: Color | undefined } {
private stylesForType(type: MessageType | undefined): { border: Color | undefined | null; background: Color | undefined | null; foreground: Color | undefined | null } {
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 };
......@@ -533,7 +533,7 @@ export class HistoryInputBox extends InputBox implements IHistoryNavigationWidge
private readonly history: HistoryNavigator<string>;
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, options: IHistoryInputOptions) {
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider | undefined, options: IHistoryInputOptions) {
super(container, contextViewProvider, options);
this.history = new HistoryNavigator<string>(options.history, 100);
}
......
......@@ -111,7 +111,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
private _replaceFocusTracker: dom.IFocusTracker;
private _replaceInputFocused: IContextKey<boolean>;
private _viewZone: FindWidgetViewZone;
private _viewZoneId: number;
private _viewZoneId?: number;
private _resizeSash: Sash;
private _resized: boolean;
......@@ -210,7 +210,9 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
return;
}
this._codeEditor.changeViewZones((accessor) => {
accessor.removeZone(this._viewZoneId);
if (this._viewZoneId) {
accessor.removeZone(this._viewZoneId);
}
this._viewZoneId = undefined;
});
}));
......@@ -239,7 +241,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
return this._domNode;
}
public getPosition(): IOverlayWidgetPosition {
public getPosition(): IOverlayWidgetPosition | null {
if (this._isVisible) {
return {
preference: OverlayWidgetPositionPreference.TOP_RIGHT_CORNER
......@@ -401,8 +403,8 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
if (!this._isVisible) {
this._isVisible = true;
let selection = this._codeEditor.getSelection();
let isSelection = selection ? (selection.startLineNumber !== selection.endLineNumber || selection.startColumn !== selection.endColumn) : false;
const selection = this._codeEditor.getSelection();
const isSelection = selection ? (selection.startLineNumber !== selection.endLineNumber || selection.startColumn !== selection.endColumn) : false;
if (isSelection && this._codeEditor.getConfiguration().contribInfo.find.autoFindInSelection) {
this._toggleSelectionFind.checked = true;
} else {
......@@ -425,24 +427,27 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
let adjustEditorScrollTop = true;
if (this._codeEditor.getConfiguration().contribInfo.find.seedSearchStringFromSelection && selection) {
let editorCoords = dom.getDomNodePagePosition(this._codeEditor.getDomNode());
let startCoords = this._codeEditor.getScrolledVisiblePosition(selection.getStartPosition());
let startLeft = editorCoords.left + startCoords.left;
let startTop = startCoords.top;
if (startTop < this._viewZone.heightInPx) {
if (selection.endLineNumber > selection.startLineNumber) {
adjustEditorScrollTop = false;
}
const domNode = this._codeEditor.getDomNode();
if (domNode) {
const editorCoords = dom.getDomNodePagePosition(domNode);
const startCoords = this._codeEditor.getScrolledVisiblePosition(selection.getStartPosition());
const startLeft = editorCoords.left + (startCoords ? startCoords.left : 0);
const startTop = startCoords ? startCoords.top : 0;
if (startTop < this._viewZone.heightInPx) {
if (selection.endLineNumber > selection.startLineNumber) {
adjustEditorScrollTop = false;
}
let leftOfFindWidget = dom.getTopLeftOffset(this._domNode).left;
if (startLeft > leftOfFindWidget) {
adjustEditorScrollTop = false;
}
let endCoords = this._codeEditor.getScrolledVisiblePosition(selection.getEndPosition());
let endLeft = editorCoords.left + endCoords.left;
if (endLeft > leftOfFindWidget) {
adjustEditorScrollTop = false;
const leftOfFindWidget = dom.getTopLeftOffset(this._domNode).left;
if (startLeft > leftOfFindWidget) {
adjustEditorScrollTop = false;
}
const endCoords = this._codeEditor.getScrolledVisiblePosition(selection.getEndPosition());
const endLeft = editorCoords.left + (endCoords ? endCoords.left : 0);
if (endLeft > leftOfFindWidget) {
adjustEditorScrollTop = false;
}
}
}
}
......@@ -609,12 +614,16 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
}
private _updateSearchScope(): void {
if (!this._codeEditor.hasModel()) {
return;
}
if (this._toggleSelectionFind.checked) {
let selection = this._codeEditor.getSelection();
if (selection.endColumn === 1 && selection.endLineNumber > selection.startLineNumber) {
selection = selection.setEndPosition(selection.endLineNumber - 1, this._codeEditor.getModel().getLineMaxColumn(selection.endLineNumber - 1));
}
let currentMatch = this._state.currentMatch;
const currentMatch = this._state.currentMatch;
if (selection.startLineNumber !== selection.endLineNumber) {
if (!Range.equalsRange(selection, currentMatch)) {
// Reseed find scope
......@@ -725,7 +734,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
appendCaseSensitiveLabel: this._keybindingLabelFor(FIND_IDS.ToggleCaseSensitiveCommand),
appendWholeWordsLabel: this._keybindingLabelFor(FIND_IDS.ToggleWholeWordCommand),
appendRegexLabel: this._keybindingLabelFor(FIND_IDS.ToggleRegexCommand),
validation: (value: string): InputBoxMessage => {
validation: (value: string): InputBoxMessage | null => {
if (value.length === 0) {
return null;
}
......@@ -806,15 +815,17 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
title: NLS_TOGGLE_SELECTION_FIND_TITLE + this._keybindingLabelFor(FIND_IDS.ToggleSearchScopeCommand),
onChange: () => {
if (this._toggleSelectionFind.checked) {
let selection = this._codeEditor.getSelection();
if (selection.endColumn === 1 && selection.endLineNumber > selection.startLineNumber) {
selection = selection.setEndPosition(selection.endLineNumber - 1, this._codeEditor.getModel().getLineMaxColumn(selection.endLineNumber - 1));
}
if (!selection.isEmpty()) {
this._state.change({ searchScope: selection }, true);
if (this._codeEditor.hasModel()) {
let selection = this._codeEditor.getSelection();
if (selection.endColumn === 1 && selection.endLineNumber > selection.startLineNumber) {
selection = selection.setEndPosition(selection.endLineNumber - 1, this._codeEditor.getModel().getLineMaxColumn(selection.endLineNumber - 1));
}
if (!selection.isEmpty()) {
this._state.change({ searchScope: selection }, true);
}
}
} else {
this._state.change({ searchScope: null }, true);
this._state.change({ searchScope: undefined }, true);
}
}
}));
......@@ -824,7 +835,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
label: NLS_CLOSE_BTN_LABEL + this._keybindingLabelFor(FIND_IDS.CloseFindWidgetCommand),
className: 'close-fw',
onTrigger: () => {
this._state.change({ isRevealed: false, searchScope: null }, false);
this._state.change({ isRevealed: false, searchScope: undefined }, false);
},
onKeyDown: (e) => {
if (e.equals(KeyCode.Tab)) {
......@@ -850,7 +861,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
let replaceInput = document.createElement('div');
replaceInput.className = 'replace-input';
replaceInput.style.width = REPLACE_INPUT_AREA_WIDTH + 'px';
this._replaceInputBox = this._register(new ContextScopedHistoryInputBox(replaceInput, null, {
this._replaceInputBox = this._register(new ContextScopedHistoryInputBox(replaceInput, void 0, {
ariaLabel: NLS_REPLACE_INPUT_LABEL,
placeholder: NLS_REPLACE_INPUT_PLACEHOLDER,
history: []
......@@ -950,8 +961,8 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
return;
}
let inputBoxWidth = width - FIND_ALL_CONTROLS_WIDTH;
let maxWidth = parseFloat(dom.getComputedStyle(this._domNode).maxWidth) || 0;
const inputBoxWidth = width - FIND_ALL_CONTROLS_WIDTH;
const maxWidth = parseFloat(dom.getComputedStyle(this._domNode).maxWidth!) || 0;
if (width > maxWidth) {
return;
}
......@@ -1119,7 +1130,7 @@ export class SimpleButton extends Widget {
// theming
registerThemingParticipant((theme, collector) => {
const addBackgroundColorRule = (selector: string, color: Color): void => {
const addBackgroundColorRule = (selector: string, color: Color | null): void => {
if (color) {
collector.addRule(`.monaco-editor ${selector} { background-color: ${color}; }`);
}
......
......@@ -30,7 +30,7 @@ export function createAndBindHistoryNavigationWidgetScopedContextKeyService(cont
export class ContextScopedHistoryInputBox extends HistoryInputBox {
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, options: IHistoryInputOptions,
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider | undefined, options: IHistoryInputOptions,
@IContextKeyService contextKeyService: IContextKeyService
) {
super(container, contextViewProvider, options);
......@@ -41,7 +41,7 @@ export class ContextScopedHistoryInputBox extends HistoryInputBox {
export class ContextScopedFindInput extends FindInput {
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, options: IFindInputOptions,
constructor(container: HTMLElement | null, contextViewProvider: IContextViewProvider, options: IFindInputOptions,
@IContextKeyService contextKeyService: IContextKeyService, showFindOptions: boolean = false
) {
super(container, contextViewProvider, showFindOptions, options);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册