mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 19:44:25 +01:00
ICodeEditor.getContribution can return null
This commit is contained in:
@@ -229,7 +229,7 @@ export abstract class EditorCommand extends Command {
|
||||
/**
|
||||
* Create a command class that is bound to a certain editor contribution.
|
||||
*/
|
||||
public static bindToContribution<T extends IEditorContribution>(controllerGetter: (editor: ICodeEditor) => T): EditorControllerCommand<T> {
|
||||
public static bindToContribution<T extends IEditorContribution>(controllerGetter: (editor: ICodeEditor) => T | null): EditorControllerCommand<T> {
|
||||
return class EditorControllerCommandImpl extends EditorCommand {
|
||||
private readonly _callback: (controller: T, args: any) => void;
|
||||
|
||||
@@ -242,7 +242,7 @@ export abstract class EditorCommand extends Command {
|
||||
public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void {
|
||||
const controller = controllerGetter(editor);
|
||||
if (controller) {
|
||||
this._callback(controllerGetter(editor), args);
|
||||
this._callback(controller, args);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -351,6 +351,25 @@ export abstract class EditorAction extends EditorCommand {
|
||||
public abstract run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | Promise<void>;
|
||||
}
|
||||
|
||||
interface IEditorContributionCtorWithGet<T extends IEditorContribution> {
|
||||
get(editor: ICodeEditor): T | null;
|
||||
}
|
||||
|
||||
export abstract class EditorControllerAction<T extends IEditorContribution> extends EditorAction {
|
||||
|
||||
protected abstract controller: IEditorContributionCtorWithGet<T>;
|
||||
|
||||
run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | Promise<void> {
|
||||
const controller = this.controller.get(editor);
|
||||
if (!controller) {
|
||||
return;
|
||||
}
|
||||
return this.runControllerAction(accessor, editor, controller, args);
|
||||
}
|
||||
|
||||
abstract runControllerAction(accessor: ServicesAccessor, editor: ICodeEditor, controller: T, args: any): void | Promise<void>;
|
||||
}
|
||||
|
||||
export type EditorActionImplementation = (accessor: ServicesAccessor, editor: ICodeEditor, args: any) => boolean | Promise<void>;
|
||||
|
||||
export class MultiEditorAction extends EditorAction {
|
||||
|
||||
Reference in New Issue
Block a user