Skip to content

Commit 84c059a

Browse files
committed
Strict null check editorActions and editorCommands
1 parent 7e05804 commit 84c059a

4 files changed

Lines changed: 18 additions & 16 deletions

File tree

src/tsconfig.strictNullChecks.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@
113113
"./vs/workbench/browser/parts/editor/breadcrumbs.ts",
114114
"./vs/workbench/browser/parts/editor/breadcrumbsModel.ts",
115115
"./vs/workbench/browser/parts/editor/editor.ts",
116+
"./vs/workbench/browser/parts/editor/editorActions.ts",
117+
"./vs/workbench/browser/parts/editor/editorCommands.ts",
116118
"./vs/workbench/browser/parts/editor/editorControl.ts",
117119
"./vs/workbench/browser/parts/editor/editorDropTarget.ts",
118120
"./vs/workbench/browser/parts/editor/editorPicker.ts",

src/vs/platform/keybinding/common/keybindingsRegistry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface IKeybindingItem {
1919
}
2020

2121
export interface IKeybindings {
22-
primary: number;
22+
primary?: number;
2323
secondary?: number[];
2424
win?: {
2525
primary: number;

src/vs/workbench/browser/parts/editor/editorActions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ export class OpenNextEditor extends BaseNavigateEditorAction {
952952
// Navigate in active group if possible
953953
const activeGroup = this.editorGroupService.activeGroup;
954954
const activeGroupEditors = activeGroup.getEditors(EditorsOrder.SEQUENTIAL);
955-
const activeEditorIndex = activeGroupEditors.indexOf(activeGroup.activeEditor);
955+
const activeEditorIndex = activeGroup.activeEditor ? activeGroupEditors.indexOf(activeGroup.activeEditor) : -1;
956956
if (activeEditorIndex + 1 < activeGroupEditors.length) {
957957
return { editor: activeGroupEditors[activeEditorIndex + 1], groupId: activeGroup.id };
958958
}
@@ -987,7 +987,7 @@ export class OpenPreviousEditor extends BaseNavigateEditorAction {
987987
// Navigate in active group if possible
988988
const activeGroup = this.editorGroupService.activeGroup;
989989
const activeGroupEditors = activeGroup.getEditors(EditorsOrder.SEQUENTIAL);
990-
const activeEditorIndex = activeGroupEditors.indexOf(activeGroup.activeEditor);
990+
const activeEditorIndex = activeGroup.activeEditor ? activeGroupEditors.indexOf(activeGroup.activeEditor) : -1;
991991
if (activeEditorIndex > 0) {
992992
return { editor: activeGroupEditors[activeEditorIndex - 1], groupId: activeGroup.id };
993993
}
@@ -1020,7 +1020,7 @@ export class OpenNextEditorInGroup extends BaseNavigateEditorAction {
10201020
protected navigate(): IEditorIdentifier {
10211021
const group = this.editorGroupService.activeGroup;
10221022
const editors = group.getEditors(EditorsOrder.SEQUENTIAL);
1023-
const index = editors.indexOf(group.activeEditor);
1023+
const index = group.activeEditor ? editors.indexOf(group.activeEditor) : -1;
10241024

10251025
return { editor: index + 1 < editors.length ? editors[index + 1] : editors[0], groupId: group.id };
10261026
}
@@ -1043,7 +1043,7 @@ export class OpenPreviousEditorInGroup extends BaseNavigateEditorAction {
10431043
protected navigate(): IEditorIdentifier {
10441044
const group = this.editorGroupService.activeGroup;
10451045
const editors = group.getEditors(EditorsOrder.SEQUENTIAL);
1046-
const index = editors.indexOf(group.activeEditor);
1046+
const index = group.activeEditor ? editors.indexOf(group.activeEditor) : -1;
10471047

10481048
return { editor: index > 0 ? editors[index - 1] : editors[editors.length - 1], groupId: group.id };
10491049
}

src/vs/workbench/browser/parts/editor/editorCommands.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { URI } from 'vs/base/common/uri';
1616
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
1717
import { IListService } from 'vs/platform/list/browser/listService';
1818
import { List } from 'vs/base/browser/ui/list/listWidget';
19-
import { distinct } from 'vs/base/common/arrays';
19+
import { distinct, coalesce } from 'vs/base/common/arrays';
2020
import { IEditorGroupsService, IEditorGroup, GroupDirection, GroupLocation, GroupsOrder, preferredSideBySideGroupDirection, EditorGroupLayout } from 'vs/workbench/services/editor/common/editorGroupsService';
2121
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
2222
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
@@ -52,9 +52,9 @@ export const NAVIGATE_IN_ACTIVE_GROUP_PREFIX = 'edt active ';
5252
export const OPEN_EDITOR_AT_INDEX_COMMAND_ID = 'workbench.action.openEditorAtIndex';
5353

5454
export interface ActiveEditorMoveArguments {
55-
to?: 'first' | 'last' | 'left' | 'right' | 'up' | 'down' | 'center' | 'position' | 'previous' | 'next';
56-
by?: 'tab' | 'group';
57-
value?: number;
55+
to: 'first' | 'last' | 'left' | 'right' | 'up' | 'down' | 'center' | 'position' | 'previous' | 'next';
56+
by: 'tab' | 'group';
57+
value: number;
5858
}
5959

6060
const isActiveEditorMoveArg = function (arg: ActiveEditorMoveArguments): boolean {
@@ -357,7 +357,7 @@ function registerOpenEditorAtIndexCommands(): void {
357357
case 9: return KeyCode.KEY_9;
358358
}
359359

360-
return undefined;
360+
throw new Error('invalid index');
361361
}
362362
}
363363

@@ -409,7 +409,7 @@ function registerFocusEditorGroupAtIndexCommands(): void {
409409
case 7: return 'workbench.action.focusEighthEditorGroup';
410410
}
411411

412-
return undefined;
412+
throw new Error('Invalid index');
413413
}
414414

415415
function toKeyCode(index: number): KeyCode {
@@ -423,7 +423,7 @@ function registerFocusEditorGroupAtIndexCommands(): void {
423423
case 7: return KeyCode.KEY_8;
424424
}
425425

426-
return undefined;
426+
throw new Error('Invalid index');
427427
}
428428
}
429429

@@ -528,9 +528,9 @@ function registerCloseEditorCommands() {
528528

529529
return Promise.all(groupIds.map(groupId => {
530530
const group = editorGroupService.getGroup(groupId);
531-
const editors = contexts
531+
const editors = coalesce(contexts
532532
.filter(context => context.groupId === groupId)
533-
.map(context => typeof context.editorIndex === 'number' ? group.getEditor(context.editorIndex) : group.activeEditor);
533+
.map(context => typeof context.editorIndex === 'number' ? group.getEditor(context.editorIndex) : group.activeEditor));
534534

535535
return group.closeEditors(editors);
536536
}));
@@ -675,7 +675,7 @@ function getCommandsContext(resourceOrContext: URI | IEditorCommandsContext, con
675675
return undefined;
676676
}
677677

678-
function resolveCommandsContext(editorGroupService: IEditorGroupsService, context?: IEditorCommandsContext): { group: IEditorGroup, editor: IEditorInput, control: IEditor } {
678+
function resolveCommandsContext(editorGroupService: IEditorGroupsService, context?: IEditorCommandsContext): { group: IEditorGroup, editor?: IEditorInput, control?: IEditor } {
679679

680680
// Resolve from context
681681
let group = context && typeof context.groupId === 'number' ? editorGroupService.getGroup(context.groupId) : undefined;
@@ -689,7 +689,7 @@ function resolveCommandsContext(editorGroupService: IEditorGroupsService, contex
689689
control = group.activeControl;
690690
}
691691

692-
return { group, editor, control };
692+
return { group, editor: editor || undefined, control: control || undefined };
693693
}
694694

695695
export function getMultiSelectedEditorContexts(editorContext: IEditorCommandsContext | undefined, listService: IListService, editorGroupService: IEditorGroupsService): IEditorCommandsContext[] {

0 commit comments

Comments
 (0)