提交 1e2b78d6 编写于 作者: A Alex Dima

strict null checks (#60565)

上级 49f8bfbc
......@@ -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",
......
......@@ -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;
}
/**
......
......@@ -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);
});
}
......
......@@ -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<ICodeEditor>;
abstract getActiveCodeEditor(): ICodeEditor | null;
abstract openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable<ICodeEditor | null>;
}
export class ModelTransientSettingWatcher {
......
......@@ -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<ICodeEditor>;
getActiveCodeEditor(): ICodeEditor | null;
openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable<ICodeEditor | null>;
}
......@@ -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<ICodeEditor>;
abstract getActiveCodeEditor(): ICodeEditor | null;
abstract openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable<ICodeEditor | null>;
}
interface IModelDecorationOptionsProvider extends IDisposable {
......
......@@ -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`); };
......
......@@ -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 {
......
......@@ -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++) {
......
......@@ -103,7 +103,7 @@ export class DiffNavigator {
}
}
private _compute(lineChanges: ILineChange[]): void {
private _compute(lineChanges: ILineChange[] | null): void {
// new ranges
this.ranges = [];
......
......@@ -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);
};
......
......@@ -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.
......
......@@ -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) {
......
......@@ -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();
......
......@@ -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();
......
......@@ -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()) {
......
......@@ -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 {
......
......@@ -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;
......
......@@ -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,
},
......
......@@ -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) {
......
......@@ -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<ClickLinkMouseEvent> = this._register(new Emitter<ClickLinkMouseEvent>());
public readonly onExecute: Event<ClickLinkMouseEvent> = 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) {
......
......@@ -56,7 +56,7 @@ export class HoverOperation<Result> {
private _firstWaitScheduler: RunOnceScheduler;
private _secondWaitScheduler: RunOnceScheduler;
private _loadingMessageScheduler: RunOnceScheduler;
private _asyncComputationPromise: CancelablePromise<Result>;
private _asyncComputationPromise: CancelablePromise<Result> | null;
private _asyncComputationPromiseDone: boolean;
private _completeCallback: (r: Result) => void;
......@@ -102,7 +102,7 @@ export class HoverOperation<Result> {
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);
......
......@@ -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;
}
......
......@@ -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
}
......
......@@ -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) {
......
......@@ -33,7 +33,7 @@ export class Link implements ILink {
return this._link.range;
}
get url(): string {
get url(): string | undefined {
return this._link.url;
}
......
......@@ -570,7 +570,7 @@ class TriggerWordHighlightAction extends EditorAction {
precondition: ctxHasWordHighlights.toNegated(),
kbOpts: {
kbExpr: EditorContextKeys.editorTextFocus,
primary: null,
primary: 0,
weight: KeybindingWeight.EditorContrib
}
});
......
......@@ -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();
......
......@@ -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;
......
......@@ -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);
......
......@@ -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<ICodeEditor> {
public openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable<ICodeEditor | null> {
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 = <IRange>input.options.selection;
const selection = <IRange>(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;
}
......
......@@ -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 {
......
......@@ -32,7 +32,7 @@ export interface ICommandHandler {
export interface ICommand {
id: string;
handler: ICommandHandler;
description?: ICommandHandlerDescription;
description?: ICommandHandlerDescription | null;
}
export interface ICommandHandlerDescription {
......
......@@ -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);
......
......@@ -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');
......
......@@ -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"),
......
......@@ -14,4 +14,4 @@ import { inQuickOpenContext } from 'vs/workbench/browser/parts/quickopen/quickop
KeybindingsRegistry.registerCommandAndKeybindingRule(QuickPickManyToggle);
const registry = Registry.as<IWorkbenchActionRegistry>(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');
......@@ -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');
......
......@@ -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 })
});
......
......@@ -33,7 +33,7 @@ const fileCategory = nls.localize('file', "File");
const workbenchActionsRegistry = Registry.as<IWorkbenchActionRegistry>(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);
......
......@@ -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) {
......
......@@ -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);
......
......@@ -58,7 +58,7 @@ Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
// Register Action to Open Viewlet
Registry.as<IWorkbenchActionRegistry>(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 }
......
......@@ -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);
......
......@@ -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);
......
......@@ -566,7 +566,7 @@ suite('Keybindings Editor Model test', () => {
function registerCommandWithTitle(command: string, title: string): void {
const registry = Registry.as<IWorkbenchActionRegistry>(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[]) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册