perf - handle workbench.contrib.textInputActionsProvider (#203947) (#203958)

perf - handle `workbench.contrib.textInputActionsProvider`
This commit is contained in:
Benjamin Pasero 2024-02-01 16:49:14 +01:00 committed by GitHub
parent a3d4451154
commit 54488a73dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,12 +14,13 @@ import { isNative } from 'vs/base/common/platform';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { Event as BaseEvent } from 'vs/base/common/event';
import { Lazy } from 'vs/base/common/lazy';
export class TextInputActionsProvider extends Disposable implements IWorkbenchContribution {
static readonly ID = 'workbench.contrib.textInputActionsProvider';
private textInputActions: IAction[] = [];
private readonly textInputActions = new Lazy<IAction[]>(() => this.createActions());
constructor(
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
@ -28,13 +29,11 @@ export class TextInputActionsProvider extends Disposable implements IWorkbenchCo
) {
super();
this.createActions();
this.registerListeners();
}
private createActions(): void {
this.textInputActions.push(
private createActions(): IAction[] {
return [
// Undo/Redo
new Action('undo', localize('undo', "Undo"), undefined, true, async () => getActiveDocument().execCommand('undo')),
@ -72,7 +71,7 @@ export class TextInputActionsProvider extends Disposable implements IWorkbenchCo
// Select All
new Action('editor.action.selectAll', localize('selectAll', "Select All"), undefined, true, async () => getActiveDocument().execCommand('selectAll'))
);
];
}
private registerListeners(): void {
@ -99,10 +98,14 @@ export class TextInputActionsProvider extends Disposable implements IWorkbenchCo
this.contextMenuService.showContextMenu({
getAnchor: () => event,
getActions: () => this.textInputActions,
getActions: () => this.textInputActions.value,
getActionsContext: () => target,
});
}
}
registerWorkbenchContribution2(TextInputActionsProvider.ID, TextInputActionsProvider, WorkbenchContributionInstantiation.BlockRestore);
registerWorkbenchContribution2(
TextInputActionsProvider.ID,
TextInputActionsProvider,
WorkbenchContributionInstantiation.BlockRestore // Block to allow right-click into input fields before restore finished
);