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

Strict null check walkThroughPart

上级 6710ec0b
......@@ -523,6 +523,7 @@
"./vs/workbench/browser/composite.ts",
"./vs/workbench/browser/panel.ts",
"./vs/workbench/browser/part.ts",
"./vs/workbench/browser/parts/editor/baseEditor.ts",
"./vs/workbench/browser/parts/editor/editor.ts",
"./vs/workbench/browser/parts/editor/editorWidgets.ts",
"./vs/workbench/browser/parts/editor/rangeDecorations.ts",
......@@ -698,6 +699,8 @@
"./vs/workbench/parts/welcome/page/electron-browser/welcomePage.contribution.ts",
"./vs/workbench/parts/welcome/page/electron-browser/welcomePage.ts",
"./vs/workbench/parts/welcome/walkThrough/electron-browser/editor/editorWalkThrough.ts",
"./vs/workbench/parts/welcome/walkThrough/electron-browser/walkThroughActions.ts",
"./vs/workbench/parts/welcome/walkThrough/electron-browser/walkThroughPart.ts",
"./vs/workbench/parts/welcome/walkThrough/node/walkThroughContentProvider.ts",
"./vs/workbench/parts/welcome/walkThrough/node/walkThroughInput.ts",
"./vs/workbench/parts/welcome/walkThrough/node/walkThroughUtils.ts",
......
......@@ -40,10 +40,10 @@ export abstract class BaseEditor extends Panel implements IEditor {
readonly onDidSizeConstraintsChange: Event<{ width: number; height: number; }> = Event.None;
protected _input: EditorInput;
protected _options: EditorOptions;
protected _input: EditorInput | null;
protected _options: EditorOptions | null;
private _group: IEditorGroup;
private _group?: IEditorGroup;
constructor(
id: string,
......@@ -54,15 +54,15 @@ export abstract class BaseEditor extends Panel implements IEditor {
super(id, telemetryService, themeService, storageService);
}
get input(): EditorInput {
get input(): EditorInput | null {
return this._input;
}
get options(): EditorOptions {
get options(): EditorOptions | null {
return this._options;
}
get group(): IEditorGroup {
get group(): IEditorGroup | undefined {
return this._group;
}
......@@ -129,7 +129,7 @@ export abstract class BaseEditor extends Panel implements IEditor {
* @param visible the state of visibility of this editor
* @param group the editor group this editor is in.
*/
protected setEditorVisible(visible: boolean, group: IEditorGroup): void {
protected setEditorVisible(visible: boolean, group: IEditorGroup | undefined): void {
this._group = group;
}
......@@ -211,9 +211,9 @@ export class EditorMemento<T> implements IEditorMemento<T> {
}
}
loadEditorState(group: IEditorGroup, resource: URI): T;
loadEditorState(group: IEditorGroup, editor: EditorInput): T;
loadEditorState(group: IEditorGroup, resourceOrEditor: URI | EditorInput): T {
loadEditorState(group: IEditorGroup, resource: URI): T | undefined;
loadEditorState(group: IEditorGroup, editor: EditorInput): T | undefined;
loadEditorState(group: IEditorGroup, resourceOrEditor: URI | EditorInput): T | undefined {
const resource = this.doGetResource(resourceOrEditor);
if (!resource || !group) {
return undefined; // we are not in a good state to load any state for a resource
......@@ -247,7 +247,7 @@ export class EditorMemento<T> implements IEditorMemento<T> {
}
}
private doGetResource(resourceOrEditor: URI | EditorInput): URI {
private doGetResource(resourceOrEditor: URI | EditorInput): URI | null {
if (resourceOrEditor instanceof EditorInput) {
return resourceOrEditor.getResource();
}
......
......@@ -46,17 +46,17 @@ export interface IEditor {
/**
* The assigned input of this editor.
*/
input: IEditorInput;
input: IEditorInput | null;
/**
* The assigned options of this editor.
*/
options: IEditorOptions;
options: IEditorOptions | null;
/**
* The assigned group this editor is showing in.
*/
group: IEditorGroup;
group: IEditorGroup | undefined;
/**
* The minimum width of this editor.
......@@ -91,7 +91,7 @@ export interface IEditor {
/**
* Returns the underlying control of this editor.
*/
getControl(): IEditorControl;
getControl(): IEditorControl | null;
/**
* Asks the underlying control to focus.
......@@ -1007,8 +1007,8 @@ export interface IEditorMemento<T> {
saveEditorState(group: IEditorGroup, resource: URI, state: T): void;
saveEditorState(group: IEditorGroup, editor: EditorInput, state: T): void;
loadEditorState(group: IEditorGroup, resource: URI): T;
loadEditorState(group: IEditorGroup, editor: EditorInput): T;
loadEditorState(group: IEditorGroup, resource: URI): T | undefined;
loadEditorState(group: IEditorGroup, editor: EditorInput): T | undefined;
clearEditorState(resource: URI, group?: IEditorGroup): void;
clearEditorState(editor: EditorInput, group?: IEditorGroup): void;
......
......@@ -437,7 +437,7 @@ export class WalkThroughPart extends BaseEditor {
private expandMacros(input: string) {
return input.replace(/kb\(([a-z.\d\-]+)\)/gi, (match: string, kb: string) => {
const keybinding = this.keybindingService.lookupKeybinding(kb);
const shortcut = keybinding ? keybinding.getLabel() : UNBOUND_COMMAND;
const shortcut = keybinding ? keybinding.getLabel() || '' : UNBOUND_COMMAND;
return `<span class="shortcut">${strings.escape(shortcut)}</span>`;
});
}
......@@ -447,7 +447,7 @@ export class WalkThroughPart extends BaseEditor {
Array.prototype.forEach.call(keys, (key: Element) => {
const command = key.getAttribute('data-command');
const keybinding = command && this.keybindingService.lookupKeybinding(command);
const label = keybinding ? keybinding.getLabel() : UNBOUND_COMMAND;
const label = keybinding ? keybinding.getLabel() || '' : UNBOUND_COMMAND;
while (key.firstChild) {
key.removeChild(key.firstChild);
}
......@@ -477,18 +477,22 @@ export class WalkThroughPart extends BaseEditor {
private saveTextEditorViewState(input: WalkThroughInput): void {
const scrollPosition = this.scrollbar.getScrollPosition();
this.editorMemento.saveEditorState(this.group, input, {
viewState: {
scrollTop: scrollPosition.scrollTop,
scrollLeft: scrollPosition.scrollLeft
}
});
if (this.group) {
this.editorMemento.saveEditorState(this.group, input, {
viewState: {
scrollTop: scrollPosition.scrollTop,
scrollLeft: scrollPosition.scrollLeft
}
});
}
}
private loadTextEditorViewState(input: WalkThroughInput) {
const state = this.editorMemento.loadEditorState(this.group, input);
if (state) {
this.scrollbar.setScrollPosition(state.viewState);
if (this.group) {
const state = this.editorMemento.loadEditorState(this.group, input);
if (state) {
this.scrollbar.setScrollPosition(state.viewState);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册