Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/common/editorAction.ts
3292 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { IEditorAction } from './editorCommon.js';
7
import { ICommandMetadata } from '../../platform/commands/common/commands.js';
8
import { ContextKeyExpression, IContextKeyService } from '../../platform/contextkey/common/contextkey.js';
9
10
export class InternalEditorAction implements IEditorAction {
11
12
constructor(
13
public readonly id: string,
14
public readonly label: string,
15
public readonly alias: string,
16
public readonly metadata: ICommandMetadata | undefined,
17
private readonly _precondition: ContextKeyExpression | undefined,
18
private readonly _run: (args: unknown) => Promise<void>,
19
private readonly _contextKeyService: IContextKeyService
20
) { }
21
22
public isSupported(): boolean {
23
return this._contextKeyService.contextMatchesRules(this._precondition);
24
}
25
26
public run(args: unknown): Promise<void> {
27
if (!this.isSupported()) {
28
return Promise.resolve(undefined);
29
}
30
31
return this._run(args);
32
}
33
}
34
35