提交 9d667371 编写于 作者: M Matt Bierner

Strict null fixes related to activeEditor now possibly being undefined

上级 ea755ec3
...@@ -422,7 +422,7 @@ export function splitEditor(editorGroupService: IEditorGroupsService, direction: ...@@ -422,7 +422,7 @@ export function splitEditor(editorGroupService: IEditorGroupsService, direction:
const newGroup = editorGroupService.addGroup(sourceGroup, direction); const newGroup = editorGroupService.addGroup(sourceGroup, direction);
// Split editor (if it can be split) // Split editor (if it can be split)
let editorToCopy: IEditorInput; let editorToCopy: IEditorInput | null;
if (context && typeof context.editorIndex === 'number') { if (context && typeof context.editorIndex === 'number') {
editorToCopy = sourceGroup.getEditor(context.editorIndex); editorToCopy = sourceGroup.getEditor(context.editorIndex);
} else { } else {
......
...@@ -53,8 +53,8 @@ export class EditorControl extends Disposable { ...@@ -53,8 +53,8 @@ export class EditorControl extends Disposable {
this.editorOperation = this._register(new LongRunningOperation(progressService)); this.editorOperation = this._register(new LongRunningOperation(progressService));
} }
get activeControl(): IActiveEditor { get activeControl(): IActiveEditor | null {
return this._activeControl; return this._activeControl as IActiveEditor | null;
} }
openEditor(editor: EditorInput, options?: EditorOptions): Promise<IOpenEditorResult> { openEditor(editor: EditorInput, options?: EditorOptions): Promise<IOpenEditorResult> {
......
...@@ -562,7 +562,7 @@ export class TabsTitleControl extends TitleControl { ...@@ -562,7 +562,7 @@ export class TabsTitleControl extends TitleControl {
disposables.push(addDisposableListener(tab, EventType.DBLCLICK, (e: MouseEvent) => { disposables.push(addDisposableListener(tab, EventType.DBLCLICK, (e: MouseEvent) => {
EventHelper.stop(e); EventHelper.stop(e);
this.group.pinEditor(this.group.getEditor(index)); this.group.pinEditor(this.group.getEditor(index) || undefined);
})); }));
// Context menu // Context menu
...@@ -670,7 +670,8 @@ export class TabsTitleControl extends TitleControl { ...@@ -670,7 +670,8 @@ export class TabsTitleControl extends TitleControl {
private updateDropFeedback(element: HTMLElement, isDND: boolean, index?: number): void { private updateDropFeedback(element: HTMLElement, isDND: boolean, index?: number): void {
const isTab = (typeof index === 'number'); const isTab = (typeof index === 'number');
const isActiveTab = isTab && this.group.isActive(this.group.getEditor(index)); const editor = typeof index === 'number' ? this.group.getEditor(index) : null;
const isActiveTab = isTab && !!editor && this.group.isActive(editor);
// Background // Background
const noDNDBackgroundColor = isTab ? this.getColor(isActiveTab ? TAB_ACTIVE_BACKGROUND : TAB_INACTIVE_BACKGROUND) : null; const noDNDBackgroundColor = isTab ? this.getColor(isActiveTab ? TAB_ACTIVE_BACKGROUND : TAB_INACTIVE_BACKGROUND) : null;
...@@ -1032,7 +1033,7 @@ export class TabsTitleControl extends TitleControl { ...@@ -1032,7 +1033,7 @@ export class TabsTitleControl extends TitleControl {
} }
} }
private getTab(editor: IEditorInput): HTMLElement { private getTab(editor: IEditorInput): HTMLElement | undefined {
const editorIndex = this.group.getIndexOfEditor(editor); const editorIndex = this.group.getIndexOfEditor(editor);
if (editorIndex >= 0) { if (editorIndex >= 0) {
return this.tabsContainer.children[editorIndex] as HTMLElement; return this.tabsContainer.children[editorIndex] as HTMLElement;
...@@ -1193,12 +1194,12 @@ registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => { ...@@ -1193,12 +1194,12 @@ registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => {
const editorGroupHeaderTabsBackground = theme.getColor(EDITOR_GROUP_HEADER_TABS_BACKGROUND); const editorGroupHeaderTabsBackground = theme.getColor(EDITOR_GROUP_HEADER_TABS_BACKGROUND);
const editorDragAndDropBackground = theme.getColor(EDITOR_DRAG_AND_DROP_BACKGROUND); const editorDragAndDropBackground = theme.getColor(EDITOR_DRAG_AND_DROP_BACKGROUND);
let adjustedTabBackground: Color; let adjustedTabBackground: Color | undefined;
if (editorGroupHeaderTabsBackground && editorBackgroundColor) { if (editorGroupHeaderTabsBackground && editorBackgroundColor) {
adjustedTabBackground = editorGroupHeaderTabsBackground.flatten(editorBackgroundColor, editorBackgroundColor, workbenchBackground); adjustedTabBackground = editorGroupHeaderTabsBackground.flatten(editorBackgroundColor, editorBackgroundColor, workbenchBackground);
} }
let adjustedTabDragBackground: Color; let adjustedTabDragBackground: Color | undefined;
if (editorGroupHeaderTabsBackground && editorBackgroundColor && editorDragAndDropBackground && editorBackgroundColor) { if (editorGroupHeaderTabsBackground && editorBackgroundColor && editorDragAndDropBackground && editorBackgroundColor) {
adjustedTabDragBackground = editorGroupHeaderTabsBackground.flatten(editorBackgroundColor, editorDragAndDropBackground, editorBackgroundColor, workbenchBackground); adjustedTabDragBackground = editorGroupHeaderTabsBackground.flatten(editorBackgroundColor, editorDragAndDropBackground, editorBackgroundColor, workbenchBackground);
} }
......
...@@ -41,7 +41,7 @@ export function getResourceForCommand(resource: URI | object, listService: IList ...@@ -41,7 +41,7 @@ export function getResourceForCommand(resource: URI | object, listService: IList
} }
} }
return toResource(editorService.activeEditor, { supportSideBySide: true }); return editorService.activeEditor ? toResource(editorService.activeEditor, { supportSideBySide: true }) : null;
} }
export function getMultiSelectedResources(resource: URI | object, listService: IListService, editorService: IEditorService): Array<URI> { export function getMultiSelectedResources(resource: URI | object, listService: IListService, editorService: IEditorService): Array<URI> {
......
...@@ -40,6 +40,10 @@ export class GotoLineAction extends QuickOpenAction { ...@@ -40,6 +40,10 @@ export class GotoLineAction extends QuickOpenAction {
run(): Promise<void> { run(): Promise<void> {
let activeTextEditorWidget = this.editorService.activeTextEditorWidget; let activeTextEditorWidget = this.editorService.activeTextEditorWidget;
if (!activeTextEditorWidget) {
return Promise.resolve();
}
if (isDiffEditor(activeTextEditorWidget)) { if (isDiffEditor(activeTextEditorWidget)) {
activeTextEditorWidget = activeTextEditorWidget.getModifiedEditor(); activeTextEditorWidget = activeTextEditorWidget.getModifiedEditor();
} }
...@@ -61,7 +65,7 @@ export class GotoLineAction extends QuickOpenAction { ...@@ -61,7 +65,7 @@ export class GotoLineAction extends QuickOpenAction {
if (restoreOptions) { if (restoreOptions) {
Event.once(this._quickOpenService.onHide)(() => { Event.once(this._quickOpenService.onHide)(() => {
activeTextEditorWidget.updateOptions(restoreOptions!); activeTextEditorWidget!.updateOptions(restoreOptions!);
}); });
} }
...@@ -92,7 +96,7 @@ class GotoLineEntry extends EditorQuickOpenEntry { ...@@ -92,7 +96,7 @@ class GotoLineEntry extends EditorQuickOpenEntry {
// Inform user about valid range if input is invalid // Inform user about valid range if input is invalid
const maxLineNumber = this.getMaxLineNumber(); const maxLineNumber = this.getMaxLineNumber();
if (this.invalidRange(maxLineNumber)) { if (this.editorService.activeTextEditorWidget && this.invalidRange(maxLineNumber)) {
const position = this.editorService.activeTextEditorWidget.getPosition(); const position = this.editorService.activeTextEditorWidget.getPosition();
if (position) { if (position) {
const currentLine = position.lineNumber; const currentLine = position.lineNumber;
...@@ -115,6 +119,9 @@ class GotoLineEntry extends EditorQuickOpenEntry { ...@@ -115,6 +119,9 @@ class GotoLineEntry extends EditorQuickOpenEntry {
private getMaxLineNumber(): number { private getMaxLineNumber(): number {
const activeTextEditorWidget = this.editorService.activeTextEditorWidget; const activeTextEditorWidget = this.editorService.activeTextEditorWidget;
if (!activeTextEditorWidget) {
return -1;
}
let model = activeTextEditorWidget.getModel(); let model = activeTextEditorWidget.getModel();
if (model && (<IDiffEditorModel>model).modified && (<IDiffEditorModel>model).original) { if (model && (<IDiffEditorModel>model).modified && (<IDiffEditorModel>model).original) {
...@@ -132,8 +139,8 @@ class GotoLineEntry extends EditorQuickOpenEntry { ...@@ -132,8 +139,8 @@ class GotoLineEntry extends EditorQuickOpenEntry {
return this.runPreview(); return this.runPreview();
} }
getInput(): IEditorInput { getInput(): IEditorInput | null {
return this.editorService.activeEditor; return this.editorService.activeEditor || null;
} }
getOptions(pinned?: boolean): ITextEditorOptions { getOptions(pinned?: boolean): ITextEditorOptions {
...@@ -153,7 +160,7 @@ class GotoLineEntry extends EditorQuickOpenEntry { ...@@ -153,7 +160,7 @@ class GotoLineEntry extends EditorQuickOpenEntry {
// Check for sideBySide use // Check for sideBySide use
const sideBySide = context.keymods.ctrlCmd; const sideBySide = context.keymods.ctrlCmd;
if (sideBySide) { if (sideBySide) {
this.editorService.openEditor(this.getInput(), this.getOptions(context.keymods.alt), SIDE_GROUP); this.editorService.openEditor(this.getInput()!, this.getOptions(context.keymods.alt), SIDE_GROUP);
} }
// Apply selection and focus // Apply selection and focus
...@@ -183,8 +190,8 @@ class GotoLineEntry extends EditorQuickOpenEntry { ...@@ -183,8 +190,8 @@ class GotoLineEntry extends EditorQuickOpenEntry {
activeTextEditorWidget.revealRangeInCenter(range, ScrollType.Smooth); activeTextEditorWidget.revealRangeInCenter(range, ScrollType.Smooth);
// Decorate if possible // Decorate if possible
if (types.isFunction(activeTextEditorWidget.changeDecorations)) { if (this.editorService.activeControl && types.isFunction(activeTextEditorWidget.changeDecorations)) {
this.handler.decorateOutline(range, activeTextEditorWidget, this.editorService.activeControl.group!); this.handler.decorateOutline(range, activeTextEditorWidget, this.editorService.activeControl.group);
} }
} }
...@@ -236,7 +243,9 @@ export class GotoLineHandler extends QuickOpenHandler { ...@@ -236,7 +243,9 @@ export class GotoLineHandler extends QuickOpenHandler {
// Remember view state to be able to restore on cancel // Remember view state to be able to restore on cancel
if (!this.lastKnownEditorViewState) { if (!this.lastKnownEditorViewState) {
const activeTextEditorWidget = this.editorService.activeTextEditorWidget; const activeTextEditorWidget = this.editorService.activeTextEditorWidget;
this.lastKnownEditorViewState = activeTextEditorWidget.saveViewState(); if (activeTextEditorWidget) {
this.lastKnownEditorViewState = activeTextEditorWidget.saveViewState();
}
} }
return Promise.resolve(new QuickOpenModel([new GotoLineEntry(searchValue, this.editorService, this)])); return Promise.resolve(new QuickOpenModel([new GotoLineEntry(searchValue, this.editorService, this)]));
......
...@@ -288,8 +288,8 @@ class SymbolEntry extends EditorQuickOpenEntryGroup { ...@@ -288,8 +288,8 @@ class SymbolEntry extends EditorQuickOpenEntryGroup {
return this.range; return this.range;
} }
getInput(): IEditorInput { getInput(): IEditorInput | null {
return this.editorService.activeEditor; return this.editorService.activeEditor || null;
} }
getOptions(pinned?: boolean): ITextEditorOptions { getOptions(pinned?: boolean): ITextEditorOptions {
...@@ -312,7 +312,7 @@ class SymbolEntry extends EditorQuickOpenEntryGroup { ...@@ -312,7 +312,7 @@ class SymbolEntry extends EditorQuickOpenEntryGroup {
// Check for sideBySide use // Check for sideBySide use
const sideBySide = context.keymods.ctrlCmd; const sideBySide = context.keymods.ctrlCmd;
if (sideBySide) { if (sideBySide) {
this.editorService.openEditor(this.getInput(), this.getOptions(context.keymods.alt), SIDE_GROUP); this.editorService.openEditor(this.getInput()!, this.getOptions(context.keymods.alt), SIDE_GROUP);
} }
// Apply selection and focus // Apply selection and focus
...@@ -337,8 +337,8 @@ class SymbolEntry extends EditorQuickOpenEntryGroup { ...@@ -337,8 +337,8 @@ class SymbolEntry extends EditorQuickOpenEntryGroup {
activeTextEditorWidget.revealRangeInCenter(range, ScrollType.Smooth); activeTextEditorWidget.revealRangeInCenter(range, ScrollType.Smooth);
// Decorate if possible // Decorate if possible
if (types.isFunction(activeTextEditorWidget.changeDecorations)) { if (this.editorService.activeControl && types.isFunction(activeTextEditorWidget.changeDecorations)) {
this.handler.decorateOutline(this.range, range, activeTextEditorWidget, this.editorService.activeControl.group!); this.handler.decorateOutline(this.range, range, activeTextEditorWidget, this.editorService.activeControl.group);
} }
} }
...@@ -401,7 +401,9 @@ export class GotoSymbolHandler extends QuickOpenHandler { ...@@ -401,7 +401,9 @@ export class GotoSymbolHandler extends QuickOpenHandler {
// Remember view state to be able to restore on cancel // Remember view state to be able to restore on cancel
if (!this.lastKnownEditorViewState) { if (!this.lastKnownEditorViewState) {
const activeTextEditorWidget = this.editorService.activeTextEditorWidget; const activeTextEditorWidget = this.editorService.activeTextEditorWidget;
this.lastKnownEditorViewState = activeTextEditorWidget.saveViewState(); if (activeTextEditorWidget) {
this.lastKnownEditorViewState = activeTextEditorWidget.saveViewState();
}
} }
// Resolve Outline Model // Resolve Outline Model
......
...@@ -217,7 +217,7 @@ export class HistoryService extends Disposable implements IHistoryService { ...@@ -217,7 +217,7 @@ export class HistoryService extends Disposable implements IHistoryService {
// Track the last edit location by tracking model content change events // Track the last edit location by tracking model content change events
// Use a debouncer to make sure to capture the correct cursor position // Use a debouncer to make sure to capture the correct cursor position
// after the model content has changed. // after the model content has changed.
this.activeEditorListeners.push(Event.debounce(activeTextEditorWidget.onDidChangeModelContent, (last, event) => event, 0)((event => this.rememberLastEditLocation(activeEditor, activeTextEditorWidget)))); this.activeEditorListeners.push(Event.debounce(activeTextEditorWidget.onDidChangeModelContent, (last, event) => event, 0)((event => this.rememberLastEditLocation(activeEditor!, activeTextEditorWidget))));
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册