From 1e2b78d601ab709ef860181a71bc305d193f52b2 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Sat, 13 Oct 2018 01:22:15 +0200 Subject: [PATCH] strict null checks (#60565) --- src/tsconfig.strictNullChecks.json | 17 +++- src/vs/editor/browser/editorBrowser.ts | 84 +++++++++++++++++-- src/vs/editor/browser/editorExtensions.ts | 10 +-- .../services/abstractCodeEditorService.ts | 4 +- .../browser/services/codeEditorService.ts | 4 +- .../browser/services/codeEditorServiceImpl.ts | 4 +- src/vs/editor/browser/view/viewImpl.ts | 4 +- .../editor/browser/widget/codeEditorWidget.ts | 4 + .../editor/browser/widget/diffEditorWidget.ts | 40 ++++----- src/vs/editor/browser/widget/diffNavigator.ts | 2 +- src/vs/editor/common/controller/cursor.ts | 2 +- src/vs/editor/common/editorCommon.ts | 2 +- .../bracketMatching/bracketMatching.ts | 20 ++--- .../caretOperations/caretOperations.ts | 3 + .../contrib/caretOperations/transpose.ts | 4 + src/vs/editor/contrib/clipboard/clipboard.ts | 20 ++++- .../contrib/comment/blockCommentCommand.ts | 13 +-- .../editor/contrib/cursorUndo/cursorUndo.ts | 12 ++- src/vs/editor/contrib/find/findController.ts | 2 +- src/vs/editor/contrib/find/findDecorations.ts | 6 +- .../goToDefinition/clickLinkGesture.ts | 8 +- src/vs/editor/contrib/hover/hoverOperation.ts | 4 +- src/vs/editor/contrib/hover/hoverWidgets.ts | 8 +- .../linesOperations/linesOperations.ts | 4 +- .../linesOperations/sortLinesCommand.ts | 4 +- src/vs/editor/contrib/links/getLinks.ts | 2 +- .../wordHighlighter/wordHighlighter.ts | 2 +- .../contrib/wordOperations/wordOperations.ts | 6 ++ .../iPadShowKeyboard/iPadShowKeyboard.ts | 7 +- .../browser/inspectTokens/inspectTokens.ts | 4 +- .../browser/standaloneCodeServiceImpl.ts | 12 +-- src/vs/monaco.d.ts | 18 ++-- src/vs/platform/commands/common/commands.ts | 2 +- .../keybinding/common/keybindingsRegistry.ts | 8 +- .../parts/editor/editor.contribution.ts | 4 +- .../browser/parts/editor/editorCommands.ts | 2 +- .../quickinput/quickInput.contribution.ts | 2 +- .../parts/quickopen/quickopen.contribution.ts | 8 +- src/vs/workbench/electron-browser/commands.ts | 4 +- .../electron-browser/main.contribution.ts | 2 +- .../preferences.contribution.ts | 8 +- .../browser/quickopen.contribution.ts | 2 +- .../scm/electron-browser/scm.contribution.ts | 2 +- .../parts/terminal/common/terminalCommands.ts | 2 +- .../electron-browser/terminal.contribution.ts | 26 +++--- .../common/keybindingsEditorModel.test.ts | 2 +- 46 files changed, 260 insertions(+), 150 deletions(-) diff --git a/src/tsconfig.strictNullChecks.json b/src/tsconfig.strictNullChecks.json index 03cdfd0f321..c2873c25dd2 100644 --- a/src/tsconfig.strictNullChecks.json +++ b/src/tsconfig.strictNullChecks.json @@ -5,7 +5,7 @@ "strictNullChecks": true }, "include": [ - "./typings", + "./typings" ], "files": [ "./vs/base/browser/browser.ts", @@ -264,21 +264,36 @@ "./vs/editor/common/viewModel/viewModel.ts", "./vs/editor/common/viewModel/viewModelDecorations.ts", "./vs/editor/common/viewModel/viewModelImpl.ts", + "./vs/editor/contrib/bracketMatching/bracketMatching.ts", + "./vs/editor/contrib/caretOperations/caretOperations.ts", "./vs/editor/contrib/caretOperations/moveCaretCommand.ts", + "./vs/editor/contrib/caretOperations/transpose.ts", + "./vs/editor/contrib/clipboard/clipboard.ts", "./vs/editor/contrib/codeAction/codeActionTrigger.ts", "./vs/editor/contrib/colorPicker/colorPickerModel.ts", + "./vs/editor/contrib/comment/blockCommentCommand.ts", + "./vs/editor/contrib/cursorUndo/cursorUndo.ts", "./vs/editor/contrib/dnd/dragAndDropCommand.ts", "./vs/editor/contrib/find/findState.ts", "./vs/editor/contrib/find/replaceAllCommand.ts", "./vs/editor/contrib/find/replacePattern.ts", "./vs/editor/contrib/fontZoom/fontZoom.ts", + "./vs/editor/contrib/goToDefinition/clickLinkGesture.ts", "./vs/editor/contrib/hover/getHover.ts", + "./vs/editor/contrib/hover/hoverOperation.ts", + "./vs/editor/contrib/hover/hoverWidgets.ts", "./vs/editor/contrib/indentation/indentUtils.ts", "./vs/editor/contrib/inPlaceReplace/inPlaceReplaceCommand.ts", "./vs/editor/contrib/linesOperations/copyLinesCommand.ts", + "./vs/editor/contrib/linesOperations/deleteLinesCommand.ts", + "./vs/editor/contrib/linesOperations/sortLinesCommand.ts", + "./vs/editor/contrib/links/getLinks.ts", "./vs/editor/contrib/quickOpen/quickOpen.ts", "./vs/editor/contrib/toggleTabFocusMode/toggleTabFocusMode.ts", + "./vs/editor/contrib/wordOperations/wordOperations.ts", "./vs/editor/editor.worker.ts", + "./vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts", + "./vs/editor/standalone/browser/standaloneCodeServiceImpl.ts", "./vs/editor/standalone/common/monarch/monarchCommon.ts", "./vs/editor/standalone/common/monarch/monarchCompile.ts", "./vs/editor/standalone/common/monarch/monarchTypes.ts", diff --git a/src/vs/editor/browser/editorBrowser.ts b/src/vs/editor/browser/editorBrowser.ts index 955505c2f13..9f53afd1eca 100644 --- a/src/vs/editor/browser/editorBrowser.ts +++ b/src/vs/editor/browser/editorBrowser.ts @@ -64,7 +64,7 @@ export interface IViewZone { /** * An optional dom node for the view zone that will be placed in the margin area. */ - marginDomNode?: HTMLElement; + marginDomNode?: HTMLElement | null; /** * Callback which gives the relative top of the view zone as it appears (taking scrolling into account). */ @@ -121,12 +121,12 @@ export interface IContentWidgetPosition { * Desired position for the content widget. * `preference` will also affect the placement. */ - position: IPosition; + position: IPosition | null; /** * Optionally, a range can be provided to further * define the position of the content widget. */ - range?: IRange; + range?: IRange | null; /** * Placement preference for position, in order of preference. */ @@ -154,7 +154,7 @@ export interface IContentWidget { * Get the placement of the content widget. * If null is returned, the content widget will be placed off screen. */ - getPosition(): IContentWidgetPosition; + getPosition(): IContentWidgetPosition | null; } /** @@ -201,7 +201,7 @@ export interface IOverlayWidget { * Get the placement of the overlay widget. * If null is returned, the overlay widget is responsible to place itself. */ - getPosition(): IOverlayWidgetPosition; + getPosition(): IOverlayWidgetPosition | null; } /** @@ -751,6 +751,74 @@ export interface ICodeEditor extends editorCommon.IEditor { * Apply the same font settings as the editor to `target`. */ applyFontInfo(target: HTMLElement): void; + + /** + * Check if the current instance has a model attached. + * @internal + */ + hasModel(): this is IActiveCodeEditor; +} + +/** + * @internal + */ +export interface IActiveCodeEditor extends ICodeEditor { + /** + * Returns the primary position of the cursor. + */ + getPosition(): Position; + + /** + * Returns the primary selection of the editor. + */ + getSelection(): Selection; + + /** + * Returns all the selections of the editor. + */ + getSelections(): Selection[]; + + /** + * Saves current view state of the editor in a serializable object. + */ + saveViewState(): editorCommon.ICodeEditorViewState; + + /** + * Type the getModel() of IEditor. + */ + getModel(): ITextModel; + + /** + * @internal + */ + _getCursors(): ICursors; + + /** + * Get all the decorations on a line (filtering out decorations from other editors). + */ + getLineDecorations(lineNumber: number): IModelDecoration[]; + + /** + * Returns the editor's dom node + */ + getDomNode(): HTMLElement; + + /** + * Get the hit test target at coordinates `clientX` and `clientY`. + * The coordinates are relative to the top-left of the viewport. + * + * @returns Hit test target or null if the coordinates fall outside the editor or the editor has no model. + */ + getTargetAtClientPoint(clientX: number, clientY: number): IMouseTarget; + + /** + * Get the visible position for `position`. + * The result position takes scrolling into account and is relative to the top left corner of the editor. + * Explanation 1: the results of this method will change for the same `position` if the user scrolls the editor. + * Explanation 2: the results of this method will not change if the container of the editor gets repositioned. + * Warning: the results of this method are innacurate for positions that are outside the current editor viewport. + */ + getScrolledVisiblePosition(position: IPosition): { top: number; left: number; height: number; }; } /** @@ -830,19 +898,19 @@ export interface IDiffEditor extends editorCommon.IEditor { /** * Get the computed diff information. */ - getLineChanges(): editorCommon.ILineChange[]; + getLineChanges(): editorCommon.ILineChange[] | null; /** * Get information based on computed diff about a line number from the original model. * If the diff computation is not finished or the model is missing, will return null. */ - getDiffLineInformationForOriginal(lineNumber: number): IDiffLineInformation; + getDiffLineInformationForOriginal(lineNumber: number): IDiffLineInformation | null; /** * Get information based on computed diff about a line number from the modified model. * If the diff computation is not finished or the model is missing, will return null. */ - getDiffLineInformationForModified(lineNumber: number): IDiffLineInformation; + getDiffLineInformationForModified(lineNumber: number): IDiffLineInformation | null; } /** diff --git a/src/vs/editor/browser/editorExtensions.ts b/src/vs/editor/browser/editorExtensions.ts index 948583b0e8d..727365c539b 100644 --- a/src/vs/editor/browser/editorExtensions.ts +++ b/src/vs/editor/browser/editorExtensions.ts @@ -39,16 +39,16 @@ export interface ICommandMenubarOptions { export interface ICommandOptions { id: string; precondition: ContextKeyExpr | null; - kbOpts?: ICommandKeybindingsOptions; + kbOpts?: ICommandKeybindingsOptions | null; description?: ICommandHandlerDescription; menubarOpts?: ICommandMenubarOptions; } export abstract class Command { public readonly id: string; public readonly precondition: ContextKeyExpr | null; - private readonly _kbOpts: ICommandKeybindingsOptions | undefined; - private readonly _menubarOpts: ICommandMenubarOptions | undefined; - private readonly _description: ICommandHandlerDescription | undefined; + private readonly _kbOpts: ICommandKeybindingsOptions | null | undefined; + private readonly _menubarOpts: ICommandMenubarOptions | null | undefined; + private readonly _description: ICommandHandlerDescription | null | undefined; constructor(opts: ICommandOptions) { this.id = opts.id; @@ -160,7 +160,7 @@ export abstract class EditorCommand extends Command { return; } - return this.runEditorCommand(editorAccessor, editor, args); + return this.runEditorCommand(editorAccessor, editor!, args); }); } diff --git a/src/vs/editor/browser/services/abstractCodeEditorService.ts b/src/vs/editor/browser/services/abstractCodeEditorService.ts index b67c731ebf5..469c512781b 100644 --- a/src/vs/editor/browser/services/abstractCodeEditorService.ts +++ b/src/vs/editor/browser/services/abstractCodeEditorService.ts @@ -125,8 +125,8 @@ export abstract class AbstractCodeEditorService extends Disposable implements IC delete this._transientWatchers[w.uri]; } - abstract getActiveCodeEditor(): ICodeEditor; - abstract openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable; + abstract getActiveCodeEditor(): ICodeEditor | null; + abstract openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable; } export class ModelTransientSettingWatcher { diff --git a/src/vs/editor/browser/services/codeEditorService.ts b/src/vs/editor/browser/services/codeEditorService.ts index 5d5f901d464..ed649b3041e 100644 --- a/src/vs/editor/browser/services/codeEditorService.ts +++ b/src/vs/editor/browser/services/codeEditorService.ts @@ -44,6 +44,6 @@ export interface ICodeEditorService { setTransientModelProperty(model: ITextModel, key: string, value: any): void; getTransientModelProperty(model: ITextModel, key: string): any; - getActiveCodeEditor(): ICodeEditor; - openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable; + getActiveCodeEditor(): ICodeEditor | null; + openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable; } diff --git a/src/vs/editor/browser/services/codeEditorServiceImpl.ts b/src/vs/editor/browser/services/codeEditorServiceImpl.ts index 27c2eaaef48..1b41b3e99e1 100644 --- a/src/vs/editor/browser/services/codeEditorServiceImpl.ts +++ b/src/vs/editor/browser/services/codeEditorServiceImpl.ts @@ -66,8 +66,8 @@ export abstract class CodeEditorServiceImpl extends AbstractCodeEditorService { return provider.getOptions(this, writable); } - abstract getActiveCodeEditor(): ICodeEditor; - abstract openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable; + abstract getActiveCodeEditor(): ICodeEditor | null; + abstract openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable; } interface IModelDecorationOptionsProvider extends IDisposable { diff --git a/src/vs/editor/browser/view/viewImpl.ts b/src/vs/editor/browser/view/viewImpl.ts index 1d677644fab..636f5aae47f 100644 --- a/src/vs/editor/browser/view/viewImpl.ts +++ b/src/vs/editor/browser/view/viewImpl.ts @@ -51,12 +51,12 @@ import { IMouseEvent } from 'vs/base/browser/mouseEvent'; export interface IContentWidgetData { widget: editorBrowser.IContentWidget; - position: editorBrowser.IContentWidgetPosition; + position: editorBrowser.IContentWidgetPosition | null; } export interface IOverlayWidgetData { widget: editorBrowser.IOverlayWidget; - position: editorBrowser.IOverlayWidgetPosition; + position: editorBrowser.IOverlayWidgetPosition | null; } const invalidFunc = () => { throw new Error(`Invalid change accessor`); }; diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index cf13f5eee3d..0ac94b2b5e4 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -1519,6 +1519,10 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE public getTelemetryData(): { [key: string]: any; } | null { return this._telemetryData; } + + public hasModel(): this is editorBrowser.IActiveCodeEditor { + return (this._modelData !== null); + } } const enum BooleanEventValue { diff --git a/src/vs/editor/browser/widget/diffEditorWidget.ts b/src/vs/editor/browser/widget/diffEditorWidget.ts index 951c28430e8..585dfea30e2 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget.ts @@ -171,7 +171,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE private _currentlyChangingViewZones: boolean; private _beginUpdateDecorationsTimeout: number; private _diffComputationToken: number; - private _lineChanges: editorCommon.ILineChange[]; + private _lineChanges: editorCommon.ILineChange[] | null; private _isVisible: boolean; private _isHandlingScrollEvent: boolean; @@ -523,7 +523,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE return editorCommon.EditorType.IDiffEditor; } - public getLineChanges(): editorCommon.ILineChange[] { + public getLineChanges(): editorCommon.ILineChange[] | null { return this._lineChanges; } @@ -642,7 +642,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE return this.modifiedEditor.getVisibleColumnFromPosition(position); } - public getPosition(): Position { + public getPosition(): Position | null { return this.modifiedEditor.getPosition(); } @@ -674,11 +674,11 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE this.modifiedEditor.revealPositionInCenterIfOutsideViewport(position, scrollType); } - public getSelection(): Selection { + public getSelection(): Selection | null { return this.modifiedEditor.getSelection(); } - public getSelections(): Selection[] { + public getSelections(): Selection[] | null { return this.modifiedEditor.getSelections(); } @@ -850,7 +850,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE private _lastOriginalWarning: URI | null = null; private _lastModifiedWarning: URI | null = null; - private static _equals(a: URI, b: URI): boolean { + private static _equals(a: URI | null, b: URI | null): boolean { if (!a && !b) { return true; } @@ -1009,7 +1009,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE } } - private _computeOverviewViewport(): { height: number; top: number; } { + private _computeOverviewViewport(): { height: number; top: number; } | null { let layoutInfo = this.modifiedEditor.getLayoutInfo(); if (!layoutInfo) { return null; @@ -1075,7 +1075,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE this._measureDomElement(true); } - private _getLineChangeAtOrBeforeLineNumber(lineNumber: number, startLineNumberExtractor: (lineChange: editorCommon.ILineChange) => number): editorCommon.ILineChange { + private _getLineChangeAtOrBeforeLineNumber(lineNumber: number, startLineNumberExtractor: (lineChange: editorCommon.ILineChange) => number): editorCommon.ILineChange | null { if (this._lineChanges.length === 0 || lineNumber < startLineNumberExtractor(this._lineChanges[0])) { // There are no changes or `lineNumber` is before the first change return null; @@ -1144,7 +1144,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE return originalEquivalentLineNumber + lineChangeOriginalLength - lineChangeModifiedLength + delta; } - public getDiffLineInformationForOriginal(lineNumber: number): editorBrowser.IDiffLineInformation { + public getDiffLineInformationForOriginal(lineNumber: number): editorBrowser.IDiffLineInformation | null { if (!this._lineChanges) { // Cannot answer that which I don't know return null; @@ -1154,7 +1154,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE }; } - public getDiffLineInformationForModified(lineNumber: number): editorBrowser.IDiffLineInformation { + public getDiffLineInformationForModified(lineNumber: number): editorBrowser.IDiffLineInformation | null { if (!this._lineChanges) { // Cannot answer that which I don't know return null; @@ -1239,7 +1239,7 @@ class ForeignViewZonesIterator { private _index: number; private _source: IEditorWhitespace[]; - public current: IEditorWhitespace; + public current: IEditorWhitespace | null; constructor(source: IEditorWhitespace[]) { this._source = source; @@ -1449,11 +1449,11 @@ abstract class ViewZonesComputer { return result; } - protected abstract _createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(): HTMLDivElement; + protected abstract _createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(): HTMLDivElement | null; - protected abstract _produceOriginalFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone; + protected abstract _produceOriginalFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null; - protected abstract _produceModifiedFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone; + protected abstract _produceModifiedFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null; } function createDecoration(startLineNumber: number, startColumn: number, endLineNumber: number, endColumn: number, options: ModelDecorationOptions) { @@ -1744,11 +1744,11 @@ class SideBySideViewZonesComputer extends ViewZonesComputer { super(lineChanges, originalForeignVZ, modifiedForeignVZ); } - protected _createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(): HTMLDivElement { + protected _createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(): HTMLDivElement | null { return null; } - protected _produceOriginalFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone { + protected _produceOriginalFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null { if (lineChangeModifiedLength > lineChangeOriginalLength) { return { afterLineNumber: Math.max(lineChange.originalStartLineNumber, lineChange.originalEndLineNumber), @@ -1759,7 +1759,7 @@ class SideBySideViewZonesComputer extends ViewZonesComputer { return null; } - protected _produceModifiedFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone { + protected _produceModifiedFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null { if (lineChangeOriginalLength > lineChangeModifiedLength) { return { afterLineNumber: Math.max(lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber), @@ -1908,13 +1908,13 @@ class InlineViewZonesComputer extends ViewZonesComputer { this.renderIndicators = renderIndicators; } - protected _createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(): HTMLDivElement { + protected _createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(): HTMLDivElement | null { let result = document.createElement('div'); result.className = 'inline-added-margin-view-zone'; return result; } - protected _produceOriginalFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone { + protected _produceOriginalFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null { let marginDomNode = document.createElement('div'); marginDomNode.className = 'inline-added-margin-view-zone'; @@ -1926,7 +1926,7 @@ class InlineViewZonesComputer extends ViewZonesComputer { }; } - protected _produceModifiedFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone { + protected _produceModifiedFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null { let decorations: InlineDecoration[] = []; if (lineChange.charChanges) { for (let j = 0, lengthJ = lineChange.charChanges.length; j < lengthJ; j++) { diff --git a/src/vs/editor/browser/widget/diffNavigator.ts b/src/vs/editor/browser/widget/diffNavigator.ts index a30ce932482..b92cb3ff688 100644 --- a/src/vs/editor/browser/widget/diffNavigator.ts +++ b/src/vs/editor/browser/widget/diffNavigator.ts @@ -103,7 +103,7 @@ export class DiffNavigator { } } - private _compute(lineChanges: ILineChange[]): void { + private _compute(lineChanges: ILineChange[] | null): void { // new ranges this.ranges = []; diff --git a/src/vs/editor/common/controller/cursor.ts b/src/vs/editor/common/controller/cursor.ts index 3b17af06eae..6dc3a0e77eb 100644 --- a/src/vs/editor/common/controller/cursor.ts +++ b/src/vs/editor/common/controller/cursor.ts @@ -786,7 +786,7 @@ class CommandExecutor { }; let hadTrackedEditOperation = false; - const addTrackedEditOperation = (selection: Range, text: string) => { + const addTrackedEditOperation = (selection: Range, text: string | null) => { hadTrackedEditOperation = true; addEditOperation(selection, text); }; diff --git a/src/vs/editor/common/editorCommon.ts b/src/vs/editor/common/editorCommon.ts index 6f3cab46393..8dbfeb3a5ed 100644 --- a/src/vs/editor/common/editorCommon.ts +++ b/src/vs/editor/common/editorCommon.ts @@ -30,7 +30,7 @@ export interface IEditOperationBuilder { * @param range The range to replace (delete). May be empty to represent a simple insert. * @param text The text to replace with. May be null to represent a simple delete. */ - addTrackedEditOperation(range: Range, text: string): void; + addTrackedEditOperation(range: Range, text: string | null): void; /** * Track `selection` when applying edit operations. diff --git a/src/vs/editor/contrib/bracketMatching/bracketMatching.ts b/src/vs/editor/contrib/bracketMatching/bracketMatching.ts index 7a7b8c01d16..93ef5e0ad7c 100644 --- a/src/vs/editor/contrib/bracketMatching/bracketMatching.ts +++ b/src/vs/editor/contrib/bracketMatching/bracketMatching.ts @@ -71,9 +71,9 @@ type Brackets = [Range, Range]; class BracketsData { public readonly position: Position; - public readonly brackets: Brackets; + public readonly brackets: Brackets | null; - constructor(position: Position, brackets: Brackets) { + constructor(position: Position, brackets: Brackets | null) { this.position = position; this.brackets = brackets; } @@ -143,12 +143,12 @@ export class BracketMatchingController extends Disposable implements editorCommo } public jumpToBracket(): void { - const model = this._editor.getModel(); - if (!model) { + if (!this._editor.hasModel()) { return; } - let newSelections = this._editor.getSelections().map(selection => { + const model = this._editor.getModel(); + const newSelections = this._editor.getSelections().map(selection => { const position = selection.getStartPosition(); // find matching brackets if position is on a bracket @@ -179,12 +179,12 @@ export class BracketMatchingController extends Disposable implements editorCommo } public selectToBracket(): void { - const model = this._editor.getModel(); - if (!model) { + if (!this._editor.hasModel()) { return; } - let newSelections: Selection[] = []; + const model = this._editor.getModel(); + const newSelections: Selection[] = []; this._editor.getSelections().forEach(selection => { const position = selection.getStartPosition(); @@ -256,14 +256,14 @@ export class BracketMatchingController extends Disposable implements editorCommo } private _recomputeBrackets(): void { - const model = this._editor.getModel(); - if (!model) { + if (!this._editor.hasModel()) { // no model => no brackets! this._lastBracketsData = []; this._lastVersionId = 0; return; } + const model = this._editor.getModel(); const versionId = model.getVersionId(); let previousData: BracketsData[] = []; if (this._lastVersionId === versionId) { diff --git a/src/vs/editor/contrib/caretOperations/caretOperations.ts b/src/vs/editor/contrib/caretOperations/caretOperations.ts index aa7ac013516..de2020f4cb5 100644 --- a/src/vs/editor/contrib/caretOperations/caretOperations.ts +++ b/src/vs/editor/contrib/caretOperations/caretOperations.ts @@ -21,6 +21,9 @@ class MoveCaretAction extends EditorAction { } public run(accessor: ServicesAccessor, editor: ICodeEditor): void { + if (!editor.hasModel()) { + return; + } let commands: ICommand[] = []; let selections = editor.getSelections(); diff --git a/src/vs/editor/contrib/caretOperations/transpose.ts b/src/vs/editor/contrib/caretOperations/transpose.ts index deea209c30c..e5811b88166 100644 --- a/src/vs/editor/contrib/caretOperations/transpose.ts +++ b/src/vs/editor/contrib/caretOperations/transpose.ts @@ -74,6 +74,10 @@ class TransposeLettersAction extends EditorAction { } public run(accessor: ServicesAccessor, editor: ICodeEditor): void { + if (!editor.hasModel()) { + return; + } + let model = editor.getModel(); let commands: ICommand[] = []; let selections = editor.getSelections(); diff --git a/src/vs/editor/contrib/clipboard/clipboard.ts b/src/vs/editor/contrib/clipboard/clipboard.ts index bbb80f1e1bd..c4ee159d9dc 100644 --- a/src/vs/editor/contrib/clipboard/clipboard.ts +++ b/src/vs/editor/contrib/clipboard/clipboard.ts @@ -59,7 +59,7 @@ abstract class ExecCommandAction extends EditorAction { class ExecCommandCutAction extends ExecCommandAction { constructor() { - let kbOpts: ICommandKeybindingsOptions = { + let kbOpts: ICommandKeybindingsOptions | null = { kbExpr: EditorContextKeys.textInputFocus, primary: KeyMod.CtrlCmd | KeyCode.KEY_X, win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_X, secondary: [KeyMod.Shift | KeyCode.Delete] }, @@ -90,6 +90,10 @@ class ExecCommandCutAction extends ExecCommandAction { } public run(accessor: ServicesAccessor, editor: ICodeEditor): void { + if (!editor.hasModel()) { + return; + } + const emptySelectionClipboard = editor.getConfiguration().emptySelectionClipboard; if (!emptySelectionClipboard && editor.getSelection().isEmpty()) { @@ -103,7 +107,7 @@ class ExecCommandCutAction extends ExecCommandAction { class ExecCommandCopyAction extends ExecCommandAction { constructor() { - let kbOpts: ICommandKeybindingsOptions = { + let kbOpts: ICommandKeybindingsOptions | null = { kbExpr: EditorContextKeys.textInputFocus, primary: KeyMod.CtrlCmd | KeyCode.KEY_C, win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_C, secondary: [KeyMod.CtrlCmd | KeyCode.Insert] }, @@ -135,6 +139,10 @@ class ExecCommandCopyAction extends ExecCommandAction { } public run(accessor: ServicesAccessor, editor: ICodeEditor): void { + if (!editor.hasModel()) { + return; + } + const emptySelectionClipboard = editor.getConfiguration().emptySelectionClipboard; if (!emptySelectionClipboard && editor.getSelection().isEmpty()) { @@ -148,7 +156,7 @@ class ExecCommandCopyAction extends ExecCommandAction { class ExecCommandPasteAction extends ExecCommandAction { constructor() { - let kbOpts: ICommandKeybindingsOptions = { + let kbOpts: ICommandKeybindingsOptions | null = { kbExpr: EditorContextKeys.textInputFocus, primary: KeyMod.CtrlCmd | KeyCode.KEY_V, win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_V, secondary: [KeyMod.Shift | KeyCode.Insert] }, @@ -190,13 +198,17 @@ class ExecCommandCopyWithSyntaxHighlightingAction extends ExecCommandAction { precondition: null, kbOpts: { kbExpr: EditorContextKeys.textInputFocus, - primary: null, + primary: 0, weight: KeybindingWeight.EditorContrib } }); } public run(accessor: ServicesAccessor, editor: ICodeEditor): void { + if (!editor.hasModel()) { + return; + } + const emptySelectionClipboard = editor.getConfiguration().emptySelectionClipboard; if (!emptySelectionClipboard && editor.getSelection().isEmpty()) { diff --git a/src/vs/editor/contrib/comment/blockCommentCommand.ts b/src/vs/editor/contrib/comment/blockCommentCommand.ts index 889339e9ada..14d67da83bb 100644 --- a/src/vs/editor/contrib/comment/blockCommentCommand.ts +++ b/src/vs/editor/contrib/comment/blockCommentCommand.ts @@ -8,14 +8,14 @@ import { Position } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; import { Selection } from 'vs/editor/common/core/selection'; import * as editorCommon from 'vs/editor/common/editorCommon'; -import { ICommentsConfiguration, LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry'; +import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry'; import { CharCode } from 'vs/base/common/charCode'; import { ITextModel, IIdentifiedSingleEditOperation } from 'vs/editor/common/model'; export class BlockCommentCommand implements editorCommon.ICommand { private _selection: Selection; - private _usedEndToken: string; + private _usedEndToken: string | null; constructor(selection: Selection) { this._selection = selection; @@ -53,7 +53,7 @@ export class BlockCommentCommand implements editorCommon.ICommand { return true; } - private _createOperationsForBlockComment(selection: Range, config: ICommentsConfiguration, model: ITextModel, builder: editorCommon.IEditOperationBuilder): void { + private _createOperationsForBlockComment(selection: Range, startToken: string, endToken: string, model: ITextModel, builder: editorCommon.IEditOperationBuilder): void { const startLineNumber = selection.startLineNumber; const startColumn = selection.startColumn; const endLineNumber = selection.endLineNumber; @@ -62,9 +62,6 @@ export class BlockCommentCommand implements editorCommon.ICommand { const startLineText = model.getLineContent(startLineNumber); const endLineText = model.getLineContent(endLineNumber); - let startToken = config.blockCommentStartToken; - let endToken = config.blockCommentEndToken; - let startTokenIndex = startLineText.lastIndexOf(startToken, startColumn - 1 + startToken.length); let endTokenIndex = endLineText.indexOf(endToken, endColumn - 1 - endToken.length); @@ -179,9 +176,7 @@ export class BlockCommentCommand implements editorCommon.ICommand { return; } - this._createOperationsForBlockComment( - this._selection, config, model, builder - ); + this._createOperationsForBlockComment(this._selection, config.blockCommentStartToken, config.blockCommentEndToken, model, builder); } public computeCursorState(model: ITextModel, helper: editorCommon.ICursorStateComputerData): Selection { diff --git a/src/vs/editor/contrib/cursorUndo/cursorUndo.ts b/src/vs/editor/contrib/cursorUndo/cursorUndo.ts index 7a8d505527a..8df1a3c07b1 100644 --- a/src/vs/editor/contrib/cursorUndo/cursorUndo.ts +++ b/src/vs/editor/contrib/cursorUndo/cursorUndo.ts @@ -47,7 +47,7 @@ export class CursorUndoController extends Disposable implements IEditorContribut private _isCursorUndo: boolean; private _undoStack: CursorState[]; - private _prevState: CursorState; + private _prevState: CursorState | null; constructor(editor: ICodeEditor) { super(); @@ -79,8 +79,8 @@ export class CursorUndoController extends Disposable implements IEditorContribut })); } - private _readState(): CursorState { - if (!this._editor.getModel()) { + private _readState(): CursorState | null { + if (!this._editor.hasModel()) { // no model => no state return null; } @@ -93,10 +93,14 @@ export class CursorUndoController extends Disposable implements IEditorContribut } public cursorUndo(): void { + if (!this._editor.hasModel()) { + return; + } + const currState = new CursorState(this._editor.getSelections()); while (this._undoStack.length > 0) { - const prevState = this._undoStack.pop(); + const prevState = this._undoStack.pop()!; if (!prevState.equals(currState)) { this._isCursorUndo = true; diff --git a/src/vs/editor/contrib/find/findController.ts b/src/vs/editor/contrib/find/findController.ts index 6f6b67791cb..263c4f3fdd3 100644 --- a/src/vs/editor/contrib/find/findController.ts +++ b/src/vs/editor/contrib/find/findController.ts @@ -455,7 +455,7 @@ export class StartFindWithSelectionAction extends EditorAction { precondition: null, kbOpts: { kbExpr: null, - primary: null, + primary: 0, mac: { primary: KeyMod.CtrlCmd | KeyCode.KEY_E, }, diff --git a/src/vs/editor/contrib/find/findDecorations.ts b/src/vs/editor/contrib/find/findDecorations.ts index 2b5a30ff8c6..5ab9a026a9b 100644 --- a/src/vs/editor/contrib/find/findDecorations.ts +++ b/src/vs/editor/contrib/find/findDecorations.ts @@ -17,9 +17,9 @@ export class FindDecorations implements IDisposable { private _editor: ICodeEditor; private _decorations: string[]; private _overviewRulerApproximateDecorations: string[]; - private _findScopeDecorationId: string; - private _rangeHighlightDecorationId: string; - private _highlightedDecorationId: string; + private _findScopeDecorationId: string | null; + private _rangeHighlightDecorationId: string | null; + private _highlightedDecorationId: string | null; private _startPosition: Position; constructor(editor: ICodeEditor) { diff --git a/src/vs/editor/contrib/goToDefinition/clickLinkGesture.ts b/src/vs/editor/contrib/goToDefinition/clickLinkGesture.ts index edc00e79cd1..4ac197ccb87 100644 --- a/src/vs/editor/contrib/goToDefinition/clickLinkGesture.ts +++ b/src/vs/editor/contrib/goToDefinition/clickLinkGesture.ts @@ -22,7 +22,7 @@ function hasModifier(e: { ctrlKey: boolean; shiftKey: boolean; altKey: boolean; */ export class ClickLinkMouseEvent { - public readonly target: IMouseTarget; + public readonly target: IMouseTarget | null; public readonly hasTriggerModifier: boolean; public readonly hasSideBySideModifier: boolean; public readonly isNoneOrSingleMouseDown: boolean; @@ -97,8 +97,8 @@ function createOptions(multiCursorModifier: 'altKey' | 'ctrlKey' | 'metaKey'): C export class ClickLinkGesture extends Disposable { - private readonly _onMouseMoveOrRelevantKeyDown: Emitter<[ClickLinkMouseEvent, ClickLinkKeyboardEvent]> = this._register(new Emitter<[ClickLinkMouseEvent, ClickLinkKeyboardEvent]>()); - public readonly onMouseMoveOrRelevantKeyDown: Event<[ClickLinkMouseEvent, ClickLinkKeyboardEvent]> = this._onMouseMoveOrRelevantKeyDown.event; + private readonly _onMouseMoveOrRelevantKeyDown: Emitter<[ClickLinkMouseEvent, ClickLinkKeyboardEvent | null]> = this._register(new Emitter<[ClickLinkMouseEvent, ClickLinkKeyboardEvent | null]>()); + public readonly onMouseMoveOrRelevantKeyDown: Event<[ClickLinkMouseEvent, ClickLinkKeyboardEvent | null]> = this._onMouseMoveOrRelevantKeyDown.event; private readonly _onExecute: Emitter = this._register(new Emitter()); public readonly onExecute: Event = this._onExecute.event; @@ -109,7 +109,7 @@ export class ClickLinkGesture extends Disposable { private readonly _editor: ICodeEditor; private _opts: ClickLinkOptions; - private lastMouseMoveEvent: ClickLinkMouseEvent; + private lastMouseMoveEvent: ClickLinkMouseEvent | null; private hasTriggerKeyOnMouseDown: boolean; constructor(editor: ICodeEditor) { diff --git a/src/vs/editor/contrib/hover/hoverOperation.ts b/src/vs/editor/contrib/hover/hoverOperation.ts index 1d3b136a306..54e3c11a0bf 100644 --- a/src/vs/editor/contrib/hover/hoverOperation.ts +++ b/src/vs/editor/contrib/hover/hoverOperation.ts @@ -56,7 +56,7 @@ export class HoverOperation { private _firstWaitScheduler: RunOnceScheduler; private _secondWaitScheduler: RunOnceScheduler; private _loadingMessageScheduler: RunOnceScheduler; - private _asyncComputationPromise: CancelablePromise; + private _asyncComputationPromise: CancelablePromise | null; private _asyncComputationPromiseDone: boolean; private _completeCallback: (r: Result) => void; @@ -102,7 +102,7 @@ export class HoverOperation { if (this._computer.computeAsync) { this._asyncComputationPromiseDone = false; - this._asyncComputationPromise = createCancelablePromise(token => this._computer.computeAsync(token)); + this._asyncComputationPromise = createCancelablePromise(token => this._computer.computeAsync!(token)); this._asyncComputationPromise.then((asyncResult: Result) => { this._asyncComputationPromiseDone = true; this._withAsyncResult(asyncResult); diff --git a/src/vs/editor/contrib/hover/hoverWidgets.ts b/src/vs/editor/contrib/hover/hoverWidgets.ts index 29ea2f8e3e8..baaae2287db 100644 --- a/src/vs/editor/contrib/hover/hoverWidgets.ts +++ b/src/vs/editor/contrib/hover/hoverWidgets.ts @@ -21,8 +21,8 @@ export class ContentHoverWidget extends Widget implements editorBrowser.IContent private _isVisible: boolean; private _containerDomNode: HTMLElement; private _domNode: HTMLElement; - protected _showAtPosition: Position; - protected _showAtRange: Range; + protected _showAtPosition: Position | null; + protected _showAtRange: Range | null; private _stoleFocus: boolean; private scrollbar: DomScrollableElement; private disposables: IDisposable[] = []; @@ -113,7 +113,7 @@ export class ContentHoverWidget extends Widget implements editorBrowser.IContent } } - public getPosition(): editorBrowser.IContentWidgetPosition { + public getPosition(): editorBrowser.IContentWidgetPosition | null { if (this.isVisible) { return { position: this._showAtPosition, @@ -233,7 +233,7 @@ export class GlyphHoverWidget extends Widget implements editorBrowser.IOverlayWi this.isVisible = false; } - public getPosition(): editorBrowser.IOverlayWidgetPosition { + public getPosition(): editorBrowser.IOverlayWidgetPosition | null { return null; } diff --git a/src/vs/editor/contrib/linesOperations/linesOperations.ts b/src/vs/editor/contrib/linesOperations/linesOperations.ts index 92fecdcd669..69838a01911 100644 --- a/src/vs/editor/contrib/linesOperations/linesOperations.ts +++ b/src/vs/editor/contrib/linesOperations/linesOperations.ts @@ -480,7 +480,7 @@ export class DeleteAllLeftAction extends AbstractDeleteAllToBoundaryAction { precondition: EditorContextKeys.writable, kbOpts: { kbExpr: EditorContextKeys.textInputFocus, - primary: null, + primary: 0, mac: { primary: KeyMod.CtrlCmd | KeyCode.Backspace }, weight: KeybindingWeight.EditorContrib } @@ -549,7 +549,7 @@ export class DeleteAllRightAction extends AbstractDeleteAllToBoundaryAction { precondition: EditorContextKeys.writable, kbOpts: { kbExpr: EditorContextKeys.textInputFocus, - primary: null, + primary: 0, mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_K, secondary: [KeyMod.CtrlCmd | KeyCode.Delete] }, weight: KeybindingWeight.EditorContrib } diff --git a/src/vs/editor/contrib/linesOperations/sortLinesCommand.ts b/src/vs/editor/contrib/linesOperations/sortLinesCommand.ts index dd8d2a533c6..6eb7a859179 100644 --- a/src/vs/editor/contrib/linesOperations/sortLinesCommand.ts +++ b/src/vs/editor/contrib/linesOperations/sortLinesCommand.ts @@ -63,7 +63,7 @@ function getSortData(model: ITextModel, selection: Selection, descending: boolea return null; } - let linesToSort = []; + let linesToSort: string[] = []; // Get the contents of the selection to be sorted. for (let lineNumber = startLineNumber; lineNumber <= endLineNumber; lineNumber++) { @@ -91,7 +91,7 @@ function getSortData(model: ITextModel, selection: Selection, descending: boolea /** * Generate commands for sorting lines on a model. */ -function sortLines(model: ITextModel, selection: Selection, descending: boolean): IIdentifiedSingleEditOperation { +function sortLines(model: ITextModel, selection: Selection, descending: boolean): IIdentifiedSingleEditOperation | null { let data = getSortData(model, selection, descending); if (!data) { diff --git a/src/vs/editor/contrib/links/getLinks.ts b/src/vs/editor/contrib/links/getLinks.ts index d0064282915..f3607812e70 100644 --- a/src/vs/editor/contrib/links/getLinks.ts +++ b/src/vs/editor/contrib/links/getLinks.ts @@ -33,7 +33,7 @@ export class Link implements ILink { return this._link.range; } - get url(): string { + get url(): string | undefined { return this._link.url; } diff --git a/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts b/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts index 1a325bca321..4fcd25fbd03 100644 --- a/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts +++ b/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts @@ -570,7 +570,7 @@ class TriggerWordHighlightAction extends EditorAction { precondition: ctxHasWordHighlights.toNegated(), kbOpts: { kbExpr: EditorContextKeys.editorTextFocus, - primary: null, + primary: 0, weight: KeybindingWeight.EditorContrib } }); diff --git a/src/vs/editor/contrib/wordOperations/wordOperations.ts b/src/vs/editor/contrib/wordOperations/wordOperations.ts index 1ebd04e53c1..468dd013f28 100644 --- a/src/vs/editor/contrib/wordOperations/wordOperations.ts +++ b/src/vs/editor/contrib/wordOperations/wordOperations.ts @@ -36,6 +36,9 @@ export abstract class MoveWordCommand extends EditorCommand { } public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void { + if (!editor.hasModel()) { + return; + } const config = editor.getConfiguration(); const wordSeparators = getMapForWordSeparators(config.wordSeparators); const model = editor.getModel(); @@ -261,6 +264,9 @@ export abstract class DeleteWordCommand extends EditorCommand { } public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void { + if (!editor.hasModel()) { + return; + } const config = editor.getConfiguration(); const wordSeparators = getMapForWordSeparators(config.wordSeparators); const model = editor.getModel(); diff --git a/src/vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts b/src/vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts index 987c6571cc3..cf3c70dc143 100644 --- a/src/vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts +++ b/src/vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts @@ -16,7 +16,7 @@ export class IPadShowKeyboard implements IEditorContribution { private static readonly ID = 'editor.contrib.iPadShowKeyboard'; private editor: ICodeEditor; - private widget: ShowKeyboardWidget; + private widget: ShowKeyboardWidget | null; private toDispose: IDisposable[]; constructor(editor: ICodeEditor) { @@ -29,14 +29,13 @@ export class IPadShowKeyboard implements IEditorContribution { } private update(): void { - const hasWidget = (!!this.widget); const shouldHaveWidget = (!this.editor.getConfiguration().readOnly); - if (!hasWidget && shouldHaveWidget) { + if (!this.widget && shouldHaveWidget) { this.widget = new ShowKeyboardWidget(this.editor); - } else if (hasWidget && !shouldHaveWidget) { + } else if (this.widget && !shouldHaveWidget) { this.widget.dispose(); this.widget = null; diff --git a/src/vs/editor/standalone/browser/inspectTokens/inspectTokens.ts b/src/vs/editor/standalone/browser/inspectTokens/inspectTokens.ts index 8724013cdea..f8c84e50ead 100644 --- a/src/vs/editor/standalone/browser/inspectTokens/inspectTokens.ts +++ b/src/vs/editor/standalone/browser/inspectTokens/inspectTokens.ts @@ -34,7 +34,7 @@ class InspectTokensController extends Disposable implements IEditorContribution private _editor: ICodeEditor; private _standaloneThemeService: IStandaloneThemeService; private _modeService: IModeService; - private _widget: InspectTokensWidget; + private _widget: InspectTokensWidget | null; constructor( editor: ICodeEditor, @@ -65,7 +65,7 @@ class InspectTokensController extends Disposable implements IEditorContribution if (this._widget) { return; } - if (!this._editor.getModel()) { + if (!this._editor.hasModel()) { return; } this._widget = new InspectTokensWidget(this._editor, this._standaloneThemeService, this._modeService); diff --git a/src/vs/editor/standalone/browser/standaloneCodeServiceImpl.ts b/src/vs/editor/standalone/browser/standaloneCodeServiceImpl.ts index de1fb892473..58b3a3b7fdb 100644 --- a/src/vs/editor/standalone/browser/standaloneCodeServiceImpl.ts +++ b/src/vs/editor/standalone/browser/standaloneCodeServiceImpl.ts @@ -15,11 +15,11 @@ import { URI } from 'vs/base/common/uri'; export class StandaloneCodeEditorServiceImpl extends CodeEditorServiceImpl { - public getActiveCodeEditor(): ICodeEditor { + public getActiveCodeEditor(): ICodeEditor | null { return null; // not supported in the standalone case } - public openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable { + public openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable { if (!source) { return Promise.resolve(null); } @@ -27,7 +27,7 @@ export class StandaloneCodeEditorServiceImpl extends CodeEditorServiceImpl { return Promise.resolve(this.doOpenEditor(source, input)); } - private doOpenEditor(editor: ICodeEditor, input: IResourceInput): ICodeEditor { + private doOpenEditor(editor: ICodeEditor, input: IResourceInput): ICodeEditor | null { const model = this.findModel(editor, input.resource); if (!model) { if (input.resource) { @@ -42,7 +42,7 @@ export class StandaloneCodeEditorServiceImpl extends CodeEditorServiceImpl { return null; } - const selection = input.options.selection; + const selection = (input.options ? input.options.selection : null); if (selection) { if (typeof selection.endLineNumber === 'number' && typeof selection.endColumn === 'number') { editor.setSelection(selection); @@ -60,9 +60,9 @@ export class StandaloneCodeEditorServiceImpl extends CodeEditorServiceImpl { return editor; } - private findModel(editor: ICodeEditor, resource: URI): ITextModel { + private findModel(editor: ICodeEditor, resource: URI): ITextModel | null { const model = editor.getModel(); - if (model.uri.toString() !== resource.toString()) { + if (model && model.uri.toString() !== resource.toString()) { return null; } diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 767217dbe2e..8c1006e4bea 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -1832,7 +1832,7 @@ declare namespace monaco.editor { * @param range The range to replace (delete). May be empty to represent a simple insert. * @param text The text to replace with. May be null to represent a simple delete. */ - addTrackedEditOperation(range: Range, text: string): void; + addTrackedEditOperation(range: Range, text: string | null): void; /** * Track `selection` when applying edit operations. * A best effort will be made to not grow/expand the selection. @@ -3503,7 +3503,7 @@ declare namespace monaco.editor { /** * An optional dom node for the view zone that will be placed in the margin area. */ - marginDomNode?: HTMLElement; + marginDomNode?: HTMLElement | null; /** * Callback which gives the relative top of the view zone as it appears (taking scrolling into account). */ @@ -3562,12 +3562,12 @@ declare namespace monaco.editor { * Desired position for the content widget. * `preference` will also affect the placement. */ - position: IPosition; + position: IPosition | null; /** * Optionally, a range can be provided to further * define the position of the content widget. */ - range?: IRange; + range?: IRange | null; /** * Placement preference for position, in order of preference. */ @@ -3595,7 +3595,7 @@ declare namespace monaco.editor { * Get the placement of the content widget. * If null is returned, the content widget will be placed off screen. */ - getPosition(): IContentWidgetPosition; + getPosition(): IContentWidgetPosition | null; } /** @@ -3642,7 +3642,7 @@ declare namespace monaco.editor { * Get the placement of the overlay widget. * If null is returned, the overlay widget is responsible to place itself. */ - getPosition(): IOverlayWidgetPosition; + getPosition(): IOverlayWidgetPosition | null; } /** @@ -4121,17 +4121,17 @@ declare namespace monaco.editor { /** * Get the computed diff information. */ - getLineChanges(): ILineChange[]; + getLineChanges(): ILineChange[] | null; /** * Get information based on computed diff about a line number from the original model. * If the diff computation is not finished or the model is missing, will return null. */ - getDiffLineInformationForOriginal(lineNumber: number): IDiffLineInformation; + getDiffLineInformationForOriginal(lineNumber: number): IDiffLineInformation | null; /** * Get information based on computed diff about a line number from the modified model. * If the diff computation is not finished or the model is missing, will return null. */ - getDiffLineInformationForModified(lineNumber: number): IDiffLineInformation; + getDiffLineInformationForModified(lineNumber: number): IDiffLineInformation | null; } export class FontInfo extends BareFontInfo { diff --git a/src/vs/platform/commands/common/commands.ts b/src/vs/platform/commands/common/commands.ts index 1a6f04b2363..7e115e47485 100644 --- a/src/vs/platform/commands/common/commands.ts +++ b/src/vs/platform/commands/common/commands.ts @@ -32,7 +32,7 @@ export interface ICommandHandler { export interface ICommand { id: string; handler: ICommandHandler; - description?: ICommandHandlerDescription; + description?: ICommandHandlerDescription | null; } export interface ICommandHandlerDescription { diff --git a/src/vs/platform/keybinding/common/keybindingsRegistry.ts b/src/vs/platform/keybinding/common/keybindingsRegistry.ts index 9a481338e3b..809ef08ebcc 100644 --- a/src/vs/platform/keybinding/common/keybindingsRegistry.ts +++ b/src/vs/platform/keybinding/common/keybindingsRegistry.ts @@ -13,7 +13,7 @@ export interface IKeybindingItem { keybinding: Keybinding; command: string; commandArgs?: any; - when: ContextKeyExpr | null; + when: ContextKeyExpr | null | undefined; weight1: number; weight2: number; } @@ -38,7 +38,7 @@ export interface IKeybindings { export interface IKeybindingRule extends IKeybindings { id: string; weight: number; - when: ContextKeyExpr | null; + when: ContextKeyExpr | null | undefined; } export interface IKeybindingRule2 { @@ -66,7 +66,7 @@ export const enum KeybindingWeight { export interface ICommandAndKeybindingRule extends IKeybindingRule { handler: ICommandHandler; - description?: ICommandHandlerDescription; + description?: ICommandHandlerDescription | null; } export interface IKeybindingsRegistry { @@ -196,7 +196,7 @@ class KeybindingsRegistryImpl implements IKeybindingsRegistry { } } - private _registerDefaultKeybinding(keybinding: Keybinding, commandId: string, weight1: number, weight2: number, when: ContextKeyExpr | null, source: KeybindingRuleSource): void { + private _registerDefaultKeybinding(keybinding: Keybinding, commandId: string, weight1: number, weight2: number, when: ContextKeyExpr | null | undefined, source: KeybindingRuleSource): void { if (source === KeybindingRuleSource.Core && OS === OperatingSystem.Windows) { if (keybinding.type === KeybindingType.Chord) { this._assertNoCtrlAlt(keybinding.firstPart, commandId); diff --git a/src/vs/workbench/browser/parts/editor/editor.contribution.ts b/src/vs/workbench/browser/parts/editor/editor.contribution.ts index cd3d5cda863..eaa16b8caa9 100644 --- a/src/vs/workbench/browser/parts/editor/editor.contribution.ts +++ b/src/vs/workbench/browser/parts/editor/editor.contribution.ts @@ -362,8 +362,8 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(NewEditorGroupLeftActi registry.registerWorkbenchAction(new SyncActionDescriptor(NewEditorGroupRightAction, NewEditorGroupRightAction.ID, NewEditorGroupRightAction.LABEL), 'View: New Editor Group to the Right', category); registry.registerWorkbenchAction(new SyncActionDescriptor(NewEditorGroupAboveAction, NewEditorGroupAboveAction.ID, NewEditorGroupAboveAction.LABEL), 'View: New Editor Group Above', category); registry.registerWorkbenchAction(new SyncActionDescriptor(NewEditorGroupBelowAction, NewEditorGroupBelowAction.ID, NewEditorGroupBelowAction.LABEL), 'View: New Editor Group Below', category); -registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateForwardAction, NavigateForwardAction.ID, NavigateForwardAction.LABEL, { primary: null, win: { primary: KeyMod.Alt | KeyCode.RightArrow }, mac: { primary: KeyMod.WinCtrl | KeyMod.Shift | KeyCode.US_MINUS }, linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_MINUS } }), 'Go Forward'); -registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateBackwardsAction, NavigateBackwardsAction.ID, NavigateBackwardsAction.LABEL, { primary: null, win: { primary: KeyMod.Alt | KeyCode.LeftArrow }, mac: { primary: KeyMod.WinCtrl | KeyCode.US_MINUS }, linux: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.US_MINUS } }), 'Go Back'); +registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateForwardAction, NavigateForwardAction.ID, NavigateForwardAction.LABEL, { primary: 0, win: { primary: KeyMod.Alt | KeyCode.RightArrow }, mac: { primary: KeyMod.WinCtrl | KeyMod.Shift | KeyCode.US_MINUS }, linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_MINUS } }), 'Go Forward'); +registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateBackwardsAction, NavigateBackwardsAction.ID, NavigateBackwardsAction.LABEL, { primary: 0, win: { primary: KeyMod.Alt | KeyCode.LeftArrow }, mac: { primary: KeyMod.WinCtrl | KeyCode.US_MINUS }, linux: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.US_MINUS } }), 'Go Back'); registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateToLastEditLocationAction, NavigateToLastEditLocationAction.ID, NavigateToLastEditLocationAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_Q) }), 'Go to Last Edit Location'); registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateLastAction, NavigateLastAction.ID, NavigateLastAction.LABEL), 'Go Last'); registry.registerWorkbenchAction(new SyncActionDescriptor(OpenPreviousEditorFromHistoryAction, OpenPreviousEditorFromHistoryAction.ID, OpenPreviousEditorFromHistoryAction.LABEL), 'Open Previous Editor from History'); diff --git a/src/vs/workbench/browser/parts/editor/editorCommands.ts b/src/vs/workbench/browser/parts/editor/editorCommands.ts index d01baf277a8..0dee127b2ef 100644 --- a/src/vs/workbench/browser/parts/editor/editorCommands.ts +++ b/src/vs/workbench/browser/parts/editor/editorCommands.ts @@ -83,7 +83,7 @@ function registerActiveEditorMoveCommand(): void { id: MOVE_ACTIVE_EDITOR_COMMAND_ID, weight: KeybindingWeight.WorkbenchContrib, when: EditorContextKeys.editorTextFocus, - primary: null, + primary: 0, handler: (accessor, args: any) => moveActiveEditor(args, accessor), description: { description: nls.localize('editorCommand.activeEditorMove.description', "Move the active editor by tabs or groups"), diff --git a/src/vs/workbench/browser/parts/quickinput/quickInput.contribution.ts b/src/vs/workbench/browser/parts/quickinput/quickInput.contribution.ts index 2f126573df4..04635f8493c 100644 --- a/src/vs/workbench/browser/parts/quickinput/quickInput.contribution.ts +++ b/src/vs/workbench/browser/parts/quickinput/quickInput.contribution.ts @@ -14,4 +14,4 @@ import { inQuickOpenContext } from 'vs/workbench/browser/parts/quickopen/quickop KeybindingsRegistry.registerCommandAndKeybindingRule(QuickPickManyToggle); const registry = Registry.as(ActionExtensions.WorkbenchActions); -registry.registerWorkbenchAction(new SyncActionDescriptor(BackAction, BackAction.ID, BackAction.LABEL, { primary: null, win: { primary: KeyMod.Alt | KeyCode.LeftArrow }, mac: { primary: KeyMod.WinCtrl | KeyCode.US_MINUS }, linux: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.US_MINUS } }, inQuickOpenContext, KeybindingWeight.WorkbenchContrib + 50), 'Back'); +registry.registerWorkbenchAction(new SyncActionDescriptor(BackAction, BackAction.ID, BackAction.LABEL, { primary: 0, win: { primary: KeyMod.Alt | KeyCode.LeftArrow }, mac: { primary: KeyMod.WinCtrl | KeyCode.US_MINUS }, linux: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.US_MINUS } }, inQuickOpenContext, KeybindingWeight.WorkbenchContrib + 50), 'Back'); diff --git a/src/vs/workbench/browser/parts/quickopen/quickopen.contribution.ts b/src/vs/workbench/browser/parts/quickopen/quickopen.contribution.ts index 21a79a56569..465cc520313 100644 --- a/src/vs/workbench/browser/parts/quickopen/quickopen.contribution.ts +++ b/src/vs/workbench/browser/parts/quickopen/quickopen.contribution.ts @@ -30,7 +30,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ id: 'workbench.action.acceptSelectedQuickOpenItem', weight: KeybindingWeight.WorkbenchContrib, when: inQuickOpenContext, - primary: null, + primary: 0, handler: accessor => { const quickOpenService = accessor.get(IQuickOpenService); quickOpenService.accept(); @@ -43,7 +43,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ id: 'workbench.action.focusQuickOpen', weight: KeybindingWeight.WorkbenchContrib, when: inQuickOpenContext, - primary: null, + primary: 0, handler: accessor => { const quickOpenService = accessor.get(IQuickOpenService); quickOpenService.focus(); @@ -69,8 +69,8 @@ MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command: { id: QUICKOPEN_ACTION_ID, title: { value: QUICKOPEN_ACION_LABEL, original: 'Go to File...' } } }); -registry.registerWorkbenchAction(new SyncActionDescriptor(QuickOpenSelectNextAction, QuickOpenSelectNextAction.ID, QuickOpenSelectNextAction.LABEL, { primary: null, mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_N } }, inQuickOpenContext, KeybindingWeight.WorkbenchContrib + 50), 'Select Next in Quick Open'); -registry.registerWorkbenchAction(new SyncActionDescriptor(QuickOpenSelectPreviousAction, QuickOpenSelectPreviousAction.ID, QuickOpenSelectPreviousAction.LABEL, { primary: null, mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_P } }, inQuickOpenContext, KeybindingWeight.WorkbenchContrib + 50), 'Select Previous in Quick Open'); +registry.registerWorkbenchAction(new SyncActionDescriptor(QuickOpenSelectNextAction, QuickOpenSelectNextAction.ID, QuickOpenSelectNextAction.LABEL, { primary: 0, mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_N } }, inQuickOpenContext, KeybindingWeight.WorkbenchContrib + 50), 'Select Next in Quick Open'); +registry.registerWorkbenchAction(new SyncActionDescriptor(QuickOpenSelectPreviousAction, QuickOpenSelectPreviousAction.ID, QuickOpenSelectPreviousAction.LABEL, { primary: 0, mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_P } }, inQuickOpenContext, KeybindingWeight.WorkbenchContrib + 50), 'Select Previous in Quick Open'); registry.registerWorkbenchAction(new SyncActionDescriptor(QuickOpenNavigateNextAction, QuickOpenNavigateNextAction.ID, QuickOpenNavigateNextAction.LABEL), 'Navigate Next in Quick Open'); registry.registerWorkbenchAction(new SyncActionDescriptor(QuickOpenNavigatePreviousAction, QuickOpenNavigatePreviousAction.ID, QuickOpenNavigatePreviousAction.LABEL), 'Navigate Previous in Quick Open'); registry.registerWorkbenchAction(new SyncActionDescriptor(RemoveFromEditorHistoryAction, RemoveFromEditorHistoryAction.ID, RemoveFromEditorHistoryAction.LABEL), 'Remove From History'); diff --git a/src/vs/workbench/electron-browser/commands.ts b/src/vs/workbench/electron-browser/commands.ts index 2253068a4ee..5b8015378f6 100644 --- a/src/vs/workbench/electron-browser/commands.ts +++ b/src/vs/workbench/electron-browser/commands.ts @@ -443,7 +443,7 @@ export function registerCommands(): void { id: 'list.focusFirstChild', weight: KeybindingWeight.WorkbenchContrib, when: WorkbenchListFocusContextKey, - primary: null, + primary: 0, handler: accessor => listFocusFirst(accessor, { fromFocused: true }) }); @@ -495,7 +495,7 @@ export function registerCommands(): void { id: 'list.focusLastChild', weight: KeybindingWeight.WorkbenchContrib, when: WorkbenchListFocusContextKey, - primary: null, + primary: 0, handler: accessor => listFocusLast(accessor, { fromFocused: true }) }); diff --git a/src/vs/workbench/electron-browser/main.contribution.ts b/src/vs/workbench/electron-browser/main.contribution.ts index 5aeae1bba94..0ca0c3f754e 100644 --- a/src/vs/workbench/electron-browser/main.contribution.ts +++ b/src/vs/workbench/electron-browser/main.contribution.ts @@ -33,7 +33,7 @@ const fileCategory = nls.localize('file', "File"); const workbenchActionsRegistry = Registry.as(Extensions.WorkbenchActions); workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(NewWindowAction, NewWindowAction.ID, NewWindowAction.LABEL, { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_N }), 'New Window'); workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CloseCurrentWindowAction, CloseCurrentWindowAction.ID, CloseCurrentWindowAction.LABEL, { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_W }), 'Close Window'); -workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(SwitchWindow, SwitchWindow.ID, SwitchWindow.LABEL, { primary: null, mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_W } }), 'Switch Window...'); +workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(SwitchWindow, SwitchWindow.ID, SwitchWindow.LABEL, { primary: 0, mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_W } }), 'Switch Window...'); workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(QuickSwitchWindow, QuickSwitchWindow.ID, QuickSwitchWindow.LABEL), 'Quick Switch Window...'); workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(QuickOpenRecentAction, QuickOpenRecentAction.ID, QuickOpenRecentAction.LABEL), 'File: Quick Open Recent...', fileCategory); diff --git a/src/vs/workbench/parts/preferences/electron-browser/preferences.contribution.ts b/src/vs/workbench/parts/preferences/electron-browser/preferences.contribution.ts index b801dd4a9ce..1b1c737047b 100644 --- a/src/vs/workbench/parts/preferences/electron-browser/preferences.contribution.ts +++ b/src/vs/workbench/parts/preferences/electron-browser/preferences.contribution.ts @@ -206,7 +206,7 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(OpenGlobalSettingsActi registry.registerWorkbenchAction(new SyncActionDescriptor(OpenGlobalKeybindingsAction, OpenGlobalKeybindingsAction.ID, OpenGlobalKeybindingsAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_S) }), 'Preferences: Open Keyboard Shortcuts', category); registry.registerWorkbenchAction(new SyncActionDescriptor(OpenDefaultKeybindingsFileAction, OpenDefaultKeybindingsFileAction.ID, OpenDefaultKeybindingsFileAction.LABEL), 'Preferences: Open Default Keyboard Shortcuts File', category); -registry.registerWorkbenchAction(new SyncActionDescriptor(OpenGlobalKeybindingsFileAction, OpenGlobalKeybindingsFileAction.ID, OpenGlobalKeybindingsFileAction.LABEL, { primary: null }), 'Preferences: Open Keyboard Shortcuts File', category); +registry.registerWorkbenchAction(new SyncActionDescriptor(OpenGlobalKeybindingsFileAction, OpenGlobalKeybindingsFileAction.ID, OpenGlobalKeybindingsFileAction.LABEL, { primary: 0 }), 'Preferences: Open Keyboard Shortcuts File', category); registry.registerWorkbenchAction(new SyncActionDescriptor(ConfigureLanguageBasedSettingsAction, ConfigureLanguageBasedSettingsAction.ID, ConfigureLanguageBasedSettingsAction.LABEL), 'Preferences: Configure Language Specific Settings...', category); KeybindingsRegistry.registerCommandAndKeybindingRule({ @@ -242,7 +242,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ id: KEYBINDINGS_EDITOR_COMMAND_RESET, weight: KeybindingWeight.WorkbenchContrib, when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS), - primary: null, + primary: 0, handler: (accessor, args: any) => { const control = accessor.get(IEditorService).activeControl as IKeybindingsEditor; if (control && control instanceof KeybindingsEditor) { @@ -296,7 +296,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ id: KEYBINDINGS_EDITOR_COMMAND_SHOW_SIMILAR, weight: KeybindingWeight.WorkbenchContrib, when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS), - primary: null, + primary: 0, handler: (accessor, args: any) => { const control = accessor.get(IEditorService).activeControl as IKeybindingsEditor; if (control) { @@ -322,7 +322,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ id: KEYBINDINGS_EDITOR_COMMAND_COPY_COMMAND, weight: KeybindingWeight.WorkbenchContrib, when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS), - primary: null, + primary: 0, handler: (accessor, args: any) => { const control = accessor.get(IEditorService).activeControl as IKeybindingsEditor; if (control) { diff --git a/src/vs/workbench/parts/quickopen/browser/quickopen.contribution.ts b/src/vs/workbench/parts/quickopen/browser/quickopen.contribution.ts index dfff582ff0e..0f8a6b8e0e8 100644 --- a/src/vs/workbench/parts/quickopen/browser/quickopen.contribution.ts +++ b/src/vs/workbench/parts/quickopen/browser/quickopen.contribution.ts @@ -39,7 +39,7 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(GotoSymbolAction, Goto const inViewsPickerContextKey = 'inViewsPicker'; const inViewsPickerContext = ContextKeyExpr.and(inQuickOpenContext, ContextKeyExpr.has(inViewsPickerContextKey)); -const viewPickerKeybinding = { primary: KeyMod.CtrlCmd | KeyCode.KEY_Q, mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_Q }, linux: { primary: null } }; +const viewPickerKeybinding = { primary: KeyMod.CtrlCmd | KeyCode.KEY_Q, mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_Q }, linux: { primary: 0 } }; const viewCategory = nls.localize('view', "View"); registry.registerWorkbenchAction(new SyncActionDescriptor(OpenViewPickerAction, OpenViewPickerAction.ID, OpenViewPickerAction.LABEL), 'View: Open View', viewCategory); diff --git a/src/vs/workbench/parts/scm/electron-browser/scm.contribution.ts b/src/vs/workbench/parts/scm/electron-browser/scm.contribution.ts index 849b8eb1cf6..7d9edddda12 100644 --- a/src/vs/workbench/parts/scm/electron-browser/scm.contribution.ts +++ b/src/vs/workbench/parts/scm/electron-browser/scm.contribution.ts @@ -58,7 +58,7 @@ Registry.as(WorkbenchExtensions.Workbench) // Register Action to Open Viewlet Registry.as(WorkbenchActionExtensions.WorkbenchActions).registerWorkbenchAction( new SyncActionDescriptor(OpenSCMViewletAction, VIEWLET_ID, localize('toggleSCMViewlet', "Show SCM"), { - primary: null, + primary: 0, win: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_G }, linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_G }, mac: { primary: KeyMod.WinCtrl | KeyMod.Shift | KeyCode.KEY_G } diff --git a/src/vs/workbench/parts/terminal/common/terminalCommands.ts b/src/vs/workbench/parts/terminal/common/terminalCommands.ts index 57cd69a7aa8..2eff4e1f6b0 100644 --- a/src/vs/workbench/parts/terminal/common/terminalCommands.ts +++ b/src/vs/workbench/parts/terminal/common/terminalCommands.ts @@ -81,7 +81,7 @@ function registerOpenTerminalAtIndexCommands(): void { id: `workbench.action.terminal.focusAtIndex${visibleIndex}`, weight: KeybindingWeight.WorkbenchContrib, when: void 0, - primary: null, + primary: 0, handler: accessor => { const terminalService = accessor.get(ITerminalService); terminalService.setActiveInstanceByIndex(terminalIndex); diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts b/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts index 2f15b591e8d..9e63c407e93 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts @@ -418,12 +418,12 @@ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(TerminalPasteAct primary: KeyMod.CtrlCmd | KeyCode.KEY_V, linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_V }, // Don't apply to Mac since cmd+v works - mac: { primary: null } + mac: { primary: 0 } }, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Paste into Active Terminal', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(SelectAllTerminalAction, SelectAllTerminalAction.ID, SelectAllTerminalAction.LABEL, { // Don't use ctrl+a by default as that would override the common go to start // of prompt shell binding - primary: null, + primary: 0, // Technically this doesn't need to be here as it will fall back to this // behavior anyway when handed to xterm.js, having this handled by VS Code // makes it easier for users to see how it works though. @@ -460,7 +460,7 @@ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ScrollToTopTermi linux: { primary: KeyMod.Shift | KeyCode.Home } }, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Scroll to Top', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ClearTerminalAction, ClearTerminalAction.ID, ClearTerminalAction.LABEL, { - primary: null, + primary: 0, mac: { primary: KeyMod.CtrlCmd | KeyCode.KEY_K } }, KEYBINDING_CONTEXT_TERMINAL_FOCUS, KeybindingWeight.WorkbenchContrib + 1), 'Terminal: Clear', category); if (platform.isWindows) { @@ -488,11 +488,11 @@ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(DeleteWordRightT mac: { primary: KeyMod.Alt | KeyCode.Delete } }, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Delete Word Right', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(MoveToLineStartTerminalAction, MoveToLineStartTerminalAction.ID, MoveToLineStartTerminalAction.LABEL, { - primary: null, + primary: 0, mac: { primary: KeyMod.CtrlCmd | KeyCode.LeftArrow } }, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Move To Line Start', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(MoveToLineEndTerminalAction, MoveToLineEndTerminalAction.ID, MoveToLineEndTerminalAction.LABEL, { - primary: null, + primary: 0, mac: { primary: KeyMod.CtrlCmd | KeyCode.RightArrow } }, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Move To Line End', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(SplitTerminalAction, SplitTerminalAction.ID, SplitTerminalAction.LABEL, { @@ -521,39 +521,39 @@ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(FocusNextPaneTer } }, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Focus Next Pane', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ResizePaneLeftTerminalAction, ResizePaneLeftTerminalAction.ID, ResizePaneLeftTerminalAction.LABEL, { - primary: null, + primary: 0, linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.LeftArrow }, mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyCode.LeftArrow } }, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Resize Pane Left', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ResizePaneRightTerminalAction, ResizePaneRightTerminalAction.ID, ResizePaneRightTerminalAction.LABEL, { - primary: null, + primary: 0, linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.RightArrow }, mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyCode.RightArrow } }, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Resize Pane Right', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ResizePaneUpTerminalAction, ResizePaneUpTerminalAction.ID, ResizePaneUpTerminalAction.LABEL, { - primary: null, + primary: 0, linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.UpArrow }, mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyCode.UpArrow } }, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Resize Pane Up', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ResizePaneDownTerminalAction, ResizePaneDownTerminalAction.ID, ResizePaneDownTerminalAction.LABEL, { - primary: null, + primary: 0, linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.DownArrow }, mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyCode.DownArrow } }, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Resize Pane Down', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ScrollToPreviousCommandAction, ScrollToPreviousCommandAction.ID, ScrollToPreviousCommandAction.LABEL, { - primary: null, + primary: 0, mac: { primary: KeyMod.CtrlCmd | KeyCode.UpArrow } }, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Scroll To Previous Command', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ScrollToNextCommandAction, ScrollToNextCommandAction.ID, ScrollToNextCommandAction.LABEL, { - primary: null, + primary: 0, mac: { primary: KeyMod.CtrlCmd | KeyCode.DownArrow } }, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Scroll To Next Command', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(SelectToPreviousCommandAction, SelectToPreviousCommandAction.ID, SelectToPreviousCommandAction.LABEL, { - primary: null, + primary: 0, mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.UpArrow } }, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Select To Previous Command', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(SelectToNextCommandAction, SelectToNextCommandAction.ID, SelectToNextCommandAction.LABEL, { - primary: null, + primary: 0, mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.DownArrow } }, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Select To Next Command', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(SelectToPreviousLineAction, SelectToPreviousLineAction.ID, SelectToPreviousLineAction.LABEL), 'Terminal: Select To Previous Line', category); diff --git a/src/vs/workbench/services/preferences/test/common/keybindingsEditorModel.test.ts b/src/vs/workbench/services/preferences/test/common/keybindingsEditorModel.test.ts index 8bdb73811c0..6909bbb226f 100644 --- a/src/vs/workbench/services/preferences/test/common/keybindingsEditorModel.test.ts +++ b/src/vs/workbench/services/preferences/test/common/keybindingsEditorModel.test.ts @@ -566,7 +566,7 @@ suite('Keybindings Editor Model test', () => { function registerCommandWithTitle(command: string, title: string): void { const registry = Registry.as(ActionExtensions.WorkbenchActions); - registry.registerWorkbenchAction(new SyncActionDescriptor(AnAction, command, title, { primary: null }), ''); + registry.registerWorkbenchAction(new SyncActionDescriptor(AnAction, command, title, { primary: 0 }), ''); } function assertKeybindingItems(actual: ResolvedKeybindingItem[], expected: ResolvedKeybindingItem[]) { -- GitLab