mirror of
https://github.com/Microsoft/vscode
synced 2024-10-04 02:14:06 +00:00
Add IEditorAction.metadata (#197442)
This commit is contained in:
parent
c2d75edf8a
commit
8513a34ce4
|
@ -97,6 +97,13 @@ declare namespace monaco.editor {
|
|||
export interface ICommandHandler {
|
||||
(...args: any[]): void;
|
||||
}
|
||||
export interface ILocalizedString {
|
||||
original: string;
|
||||
value: string;
|
||||
}
|
||||
export interface ICommandMetadata {
|
||||
readonly description: ILocalizedString | string;
|
||||
}
|
||||
#include(vs/platform/contextkey/common/contextkey): IContextKey, ContextKeyValue
|
||||
#include(vs/editor/standalone/browser/standaloneServices): IEditorOverrideServices
|
||||
#include(vs/platform/markers/common/markers): IMarker, IMarkerData, IRelatedInformation
|
||||
|
|
|
@ -104,14 +104,14 @@ export abstract class Command {
|
|||
public readonly precondition: ContextKeyExpression | undefined;
|
||||
private readonly _kbOpts: ICommandKeybindingsOptions | ICommandKeybindingsOptions[] | undefined;
|
||||
private readonly _menuOpts: ICommandMenuOptions | ICommandMenuOptions[] | undefined;
|
||||
private readonly _metadata: ICommandMetadata | undefined;
|
||||
public readonly metadata: ICommandMetadata | undefined;
|
||||
|
||||
constructor(opts: ICommandOptions) {
|
||||
this.id = opts.id;
|
||||
this.precondition = opts.precondition;
|
||||
this._kbOpts = opts.kbOpts;
|
||||
this._menuOpts = opts.menuOpts;
|
||||
this._metadata = opts.metadata;
|
||||
this.metadata = opts.metadata;
|
||||
}
|
||||
|
||||
public register(): void {
|
||||
|
@ -153,7 +153,7 @@ export abstract class Command {
|
|||
CommandsRegistry.registerCommand({
|
||||
id: this.id,
|
||||
handler: (accessor, args) => this.runCommand(accessor, args),
|
||||
metadata: this._metadata
|
||||
metadata: this.metadata
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -345,6 +345,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
|
|||
action.id,
|
||||
action.label,
|
||||
action.alias,
|
||||
action.metadata,
|
||||
action.precondition ?? undefined,
|
||||
(): Promise<void> => {
|
||||
return this._instantiationService.invokeFunction((accessor) => {
|
||||
|
|
|
@ -4,33 +4,20 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IEditorAction } from 'vs/editor/common/editorCommon';
|
||||
import { IContextKeyService, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { ICommandMetadata } from 'vs/platform/commands/common/commands';
|
||||
import { ContextKeyExpression, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
|
||||
export class InternalEditorAction implements IEditorAction {
|
||||
|
||||
public readonly id: string;
|
||||
public readonly label: string;
|
||||
public readonly alias: string;
|
||||
|
||||
private readonly _precondition: ContextKeyExpression | undefined;
|
||||
private readonly _run: (args: unknown) => Promise<void>;
|
||||
private readonly _contextKeyService: IContextKeyService;
|
||||
|
||||
constructor(
|
||||
id: string,
|
||||
label: string,
|
||||
alias: string,
|
||||
precondition: ContextKeyExpression | undefined,
|
||||
run: () => Promise<void>,
|
||||
contextKeyService: IContextKeyService
|
||||
) {
|
||||
this.id = id;
|
||||
this.label = label;
|
||||
this.alias = alias;
|
||||
this._precondition = precondition;
|
||||
this._run = run;
|
||||
this._contextKeyService = contextKeyService;
|
||||
}
|
||||
public readonly id: string,
|
||||
public readonly label: string,
|
||||
public readonly alias: string,
|
||||
public readonly metadata: ICommandMetadata | undefined,
|
||||
private readonly _precondition: ContextKeyExpression | undefined,
|
||||
private readonly _run: (args: unknown) => Promise<void>,
|
||||
private readonly _contextKeyService: IContextKeyService
|
||||
) { }
|
||||
|
||||
public isSupported(): boolean {
|
||||
return this._contextKeyService.contextMatchesRules(this._precondition);
|
||||
|
|
|
@ -15,6 +15,7 @@ import { IRange, Range } from 'vs/editor/common/core/range';
|
|||
import { ISelection, Selection } from 'vs/editor/common/core/selection';
|
||||
import { IModelDecoration, IModelDecorationsChangeAccessor, IModelDeltaDecoration, ITextModel, IValidEditOperation, OverviewRulerLane, TrackedRangeStickiness } from 'vs/editor/common/model';
|
||||
import { IModelDecorationsChangedEvent } from 'vs/editor/common/textModelEvents';
|
||||
import { ICommandMetadata } from 'vs/platform/commands/common/commands';
|
||||
|
||||
/**
|
||||
* A builder and helper for edit operations for a command.
|
||||
|
@ -155,6 +156,7 @@ export interface IEditorAction {
|
|||
readonly id: string;
|
||||
readonly label: string;
|
||||
readonly alias: string;
|
||||
readonly metadata: ICommandMetadata | undefined;
|
||||
isSupported(): boolean;
|
||||
run(args?: unknown): Promise<void>;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ class SelectToBracketAction extends EditorAction {
|
|||
alias: 'Select to Bracket',
|
||||
precondition: undefined,
|
||||
metadata: {
|
||||
description: `Select to Bracket`,
|
||||
description: nls.localize2('smartSelect.selectToBracketDescription', "Select the text inside and including the brackets or curly braces"),
|
||||
args: [{
|
||||
name: 'args',
|
||||
schema: {
|
||||
|
|
|
@ -367,6 +367,7 @@ export class StandaloneCodeEditor extends CodeEditorWidget implements IStandalon
|
|||
uniqueId,
|
||||
label,
|
||||
label,
|
||||
undefined,
|
||||
precondition,
|
||||
(...args: unknown[]) => Promise.resolve(_descriptor.run(this, ...args)),
|
||||
this._contextKeyService
|
||||
|
|
8
src/vs/monaco.d.ts
vendored
8
src/vs/monaco.d.ts
vendored
|
@ -1434,6 +1434,13 @@ declare namespace monaco.editor {
|
|||
export interface ICommandHandler {
|
||||
(...args: any[]): void;
|
||||
}
|
||||
export interface ILocalizedString {
|
||||
original: string;
|
||||
value: string;
|
||||
}
|
||||
export interface ICommandMetadata {
|
||||
readonly description: ILocalizedString | string;
|
||||
}
|
||||
|
||||
export interface IContextKey<T extends ContextKeyValue = ContextKeyValue> {
|
||||
set(value: T): void;
|
||||
|
@ -2469,6 +2476,7 @@ declare namespace monaco.editor {
|
|||
readonly id: string;
|
||||
readonly label: string;
|
||||
readonly alias: string;
|
||||
readonly metadata: ICommandMetadata | undefined;
|
||||
isSupported(): boolean;
|
||||
run(args?: unknown): Promise<void>;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue