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