From 305d5be119cf808ccb1b4b6a7ec7888349452229 Mon Sep 17 00:00:00 2001 From: SteVen Batten <6561887+sbatten@users.noreply.github.com> Date: Thu, 11 Jul 2019 00:49:28 -0700 Subject: [PATCH] implement browser clipboard service (#75293) * implement browser clipboard service * actually register the clipboard service * update all refs to newly async funcs * addressing comments * small fixes * all asyncs as a result of readText * fix unit test * cleanup for writeText refs * cleanup and reduce diff noise * qfix * address feedback --- .../snippet/test/snippetVariables.test.ts | 2 +- .../clipboard/browser/clipboardService.ts | 49 +++++++++++++++++++ .../clipboard/common/clipboardService.ts | 4 +- .../electron-browser/clipboardService.ts | 4 +- .../api/browser/mainThreadClipboard.ts | 5 +- .../notifications/notificationsActions.ts | 4 +- .../workbench/browser/web.simpleservices.ts | 40 --------------- .../contrib/debug/browser/debugActions.ts | 6 +-- .../contrib/debug/browser/debugCommands.ts | 4 +- .../workbench/contrib/debug/browser/repl.ts | 12 ++--- .../contrib/debug/browser/variablesView.ts | 3 +- .../electron-browser/extensionsActions.ts | 3 +- .../contrib/files/browser/fileActions.ts | 6 +-- .../contrib/files/browser/fileCommands.ts | 16 +++--- .../markers/browser/markers.contribution.ts | 24 ++++----- .../electron-browser/startupProfiler.ts | 18 +++---- .../preferences/browser/keybindingsEditor.ts | 8 +-- .../browser/preferences.contribution.ts | 8 +-- .../preferences/browser/settingsTree.ts | 8 +-- .../contrib/preferences/common/preferences.ts | 4 +- .../contrib/search/browser/searchActions.ts | 12 ++--- .../terminal/browser/terminalActions.ts | 4 +- .../terminal/browser/terminalInstance.ts | 4 +- .../contrib/terminal/browser/terminalPanel.ts | 8 +-- .../contrib/terminal/common/terminal.ts | 2 +- src/vs/workbench/workbench.web.main.ts | 6 +-- 26 files changed, 133 insertions(+), 131 deletions(-) create mode 100644 src/vs/platform/clipboard/browser/clipboardService.ts diff --git a/src/vs/editor/contrib/snippet/test/snippetVariables.test.ts b/src/vs/editor/contrib/snippet/test/snippetVariables.test.ts index abab5967188..3db02e45be4 100644 --- a/src/vs/editor/contrib/snippet/test/snippetVariables.test.ts +++ b/src/vs/editor/contrib/snippet/test/snippetVariables.test.ts @@ -274,7 +274,7 @@ suite('Snippet Variables Resolver', function () { let resolver: VariableResolver; const clipboardService = new class implements IClipboardService { _serviceBrand: any; - readText(): string { return readTextResult; } + async readText(): Promise { return readTextResult; } readTextSync(): any { return readTextResult; } _throw = () => { throw new Error(); }; writeText = this._throw; diff --git a/src/vs/platform/clipboard/browser/clipboardService.ts b/src/vs/platform/clipboard/browser/clipboardService.ts new file mode 100644 index 00000000000..cb546ad5b8e --- /dev/null +++ b/src/vs/platform/clipboard/browser/clipboardService.ts @@ -0,0 +1,49 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; +import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; +import { URI } from 'vs/base/common/uri'; +import { ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation'; + +export class ClipboardService implements IClipboardService { + + _serviceBrand: ServiceIdentifier; + + private _internalResourcesClipboard: URI[] | undefined; + + async writeText(text: string, type?: string): Promise { + return navigator.clipboard.writeText(text); + } + + async readText(type?: string): Promise { + return navigator.clipboard.readText(); + } + + readTextSync(): string | undefined { + return undefined; + } + + readFindText(): string { + // @ts-ignore + return undefined; + } + + writeFindText(text: string): void { } + + writeResources(resources: URI[]): void { + this._internalResourcesClipboard = resources; + } + + readResources(): URI[] { + return this._internalResourcesClipboard || []; + } + + hasResources(): boolean { + return this._internalResourcesClipboard !== undefined && this._internalResourcesClipboard.length > 0; + } +} + +registerSingleton(IClipboardService, ClipboardService, true); \ No newline at end of file diff --git a/src/vs/platform/clipboard/common/clipboardService.ts b/src/vs/platform/clipboard/common/clipboardService.ts index 75ee8724b01..84018111136 100644 --- a/src/vs/platform/clipboard/common/clipboardService.ts +++ b/src/vs/platform/clipboard/common/clipboardService.ts @@ -15,12 +15,12 @@ export interface IClipboardService { /** * Writes text to the system clipboard. */ - writeText(text: string, type?: string): void; + writeText(text: string, type?: string): Promise; /** * Reads the content of the clipboard in plain text */ - readText(type?: string): string; + readText(type?: string): Promise; readTextSync(): string | undefined; diff --git a/src/vs/platform/clipboard/electron-browser/clipboardService.ts b/src/vs/platform/clipboard/electron-browser/clipboardService.ts index 6d000b9da04..4150430af7b 100644 --- a/src/vs/platform/clipboard/electron-browser/clipboardService.ts +++ b/src/vs/platform/clipboard/electron-browser/clipboardService.ts @@ -14,11 +14,11 @@ export class ClipboardService implements IClipboardService { _serviceBrand: any; - writeText(text: string, type?: 'selection' | 'clipboard'): void { + async writeText(text: string, type?: 'selection' | 'clipboard'): Promise { clipboard.writeText(text, type); } - readText(type?: 'selection' | 'clipboard'): string { + async readText(type?: 'selection' | 'clipboard'): Promise { return clipboard.readText(type); } diff --git a/src/vs/workbench/api/browser/mainThreadClipboard.ts b/src/vs/workbench/api/browser/mainThreadClipboard.ts index 78df4a034b0..85c041c5b6e 100644 --- a/src/vs/workbench/api/browser/mainThreadClipboard.ts +++ b/src/vs/workbench/api/browser/mainThreadClipboard.ts @@ -20,11 +20,10 @@ export class MainThreadClipboard implements MainThreadClipboardShape { } $readText(): Promise { - return Promise.resolve(this._clipboardService.readText()); + return this._clipboardService.readText(); } $writeText(value: string): Promise { - this._clipboardService.writeText(value); - return Promise.resolve(); + return this._clipboardService.writeText(value); } } diff --git a/src/vs/workbench/browser/parts/notifications/notificationsActions.ts b/src/vs/workbench/browser/parts/notifications/notificationsActions.ts index c4ef92629a4..16f7f408a3e 100644 --- a/src/vs/workbench/browser/parts/notifications/notificationsActions.ts +++ b/src/vs/workbench/browser/parts/notifications/notificationsActions.ts @@ -145,9 +145,7 @@ export class CopyNotificationMessageAction extends Action { } run(notification: INotificationViewItem): Promise { - this.clipboardService.writeText(notification.message.raw); - - return Promise.resolve(); + return this.clipboardService.writeText(notification.message.raw); } } diff --git a/src/vs/workbench/browser/web.simpleservices.ts b/src/vs/workbench/browser/web.simpleservices.ts index 36fdab58002..548813c555b 100644 --- a/src/vs/workbench/browser/web.simpleservices.ts +++ b/src/vs/workbench/browser/web.simpleservices.ts @@ -8,7 +8,6 @@ import * as browser from 'vs/base/browser/browser'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { Event } from 'vs/base/common/event'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; -import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; // tslint:disable-next-line: import-patterns no-standalone-editor import { IDownloadService } from 'vs/platform/download/common/download'; import { CancellationToken } from 'vs/base/common/cancellation'; @@ -43,45 +42,6 @@ import { ClassifiedEvent, StrictPropertyCheck, GDPRClassification } from 'vs/pla import { IProcessEnvironment } from 'vs/base/common/platform'; import { toStoreData, restoreRecentlyOpened } from 'vs/platform/history/common/historyStorage'; -//#region Clipboard - -export class SimpleClipboardService implements IClipboardService { - - _serviceBrand: any; - - writeText(text: string, type?: string): void { } - - readText(type?: string): string { - // @ts-ignore - return undefined; - } - - readTextSync(): string | undefined { - return undefined; - } - - readFindText(): string { - // @ts-ignore - return undefined; - } - - writeFindText(text: string): void { } - - writeResources(resources: URI[]): void { } - - readResources(): URI[] { - return []; - } - - hasResources(): boolean { - return false; - } -} - -registerSingleton(IClipboardService, SimpleClipboardService, true); - -//#endregion - //#region Download export class SimpleDownloadService implements IDownloadService { diff --git a/src/vs/workbench/contrib/debug/browser/debugActions.ts b/src/vs/workbench/contrib/debug/browser/debugActions.ts index 0f16da0f89f..f2ed8a479ac 100644 --- a/src/vs/workbench/contrib/debug/browser/debugActions.ts +++ b/src/vs/workbench/contrib/debug/browser/debugActions.ts @@ -398,11 +398,11 @@ export class CopyValueAction extends Action { if (this.value instanceof Variable && stackFrame && session && this.value.evaluateName) { return session.evaluate(this.value.evaluateName, stackFrame.frameId, this.context).then(result => { - this.clipboardService.writeText(result.body.result); + return this.clipboardService.writeText(result.body.result); }, err => this.clipboardService.writeText(this.value.value)); } - this.clipboardService.writeText(this.value); - return Promise.resolve(undefined); + + return this.clipboardService.writeText(this.value); } } diff --git a/src/vs/workbench/contrib/debug/browser/debugCommands.ts b/src/vs/workbench/contrib/debug/browser/debugCommands.ts index 95010a4ea63..95cd771b7f3 100644 --- a/src/vs/workbench/contrib/debug/browser/debugCommands.ts +++ b/src/vs/workbench/contrib/debug/browser/debugCommands.ts @@ -71,11 +71,11 @@ export function registerCommands(): void { CommandsRegistry.registerCommand({ id: COPY_STACK_TRACE_ID, - handler: (accessor: ServicesAccessor, _: string, frame: IStackFrame) => { + handler: async (accessor: ServicesAccessor, _: string, frame: IStackFrame) => { const textResourcePropertiesService = accessor.get(ITextResourcePropertiesService); const clipboardService = accessor.get(IClipboardService); const eol = textResourcePropertiesService.getEOL(frame.source.uri); - clipboardService.writeText(frame.thread.getCallStack().map(sf => sf.toString()).join(eol)); + await clipboardService.writeText(frame.thread.getCallStack().map(sf => sf.toString()).join(eol)); } }); diff --git a/src/vs/workbench/contrib/debug/browser/repl.ts b/src/vs/workbench/contrib/debug/browser/repl.ts index 9e89ac09d99..c099ec691a9 100644 --- a/src/vs/workbench/contrib/debug/browser/repl.ts +++ b/src/vs/workbench/contrib/debug/browser/repl.ts @@ -472,16 +472,16 @@ export class Repl extends Panel implements IPrivateReplService, IHistoryNavigati private onContextMenu(e: ITreeContextMenuEvent): void { const actions: IAction[] = []; - actions.push(new Action('debug.replCopy', nls.localize('copy', "Copy"), undefined, true, () => { + actions.push(new Action('debug.replCopy', nls.localize('copy', "Copy"), undefined, true, async () => { const nativeSelection = window.getSelection(); if (nativeSelection) { - this.clipboardService.writeText(nativeSelection.toString()); + await this.clipboardService.writeText(nativeSelection.toString()); } return Promise.resolve(); })); - actions.push(new Action('workbench.debug.action.copyAll', nls.localize('copyAll', "Copy All"), undefined, true, () => { - this.clipboardService.writeText(this.getVisibleContent()); - return Promise.resolve(undefined); + actions.push(new Action('workbench.debug.action.copyAll', nls.localize('copyAll', "Copy All"), undefined, true, async () => { + await this.clipboardService.writeText(this.getVisibleContent()); + return Promise.resolve(); })); actions.push(new Action('debug.collapseRepl', nls.localize('collapse', "Collapse All"), undefined, true, () => { this.tree.collapseAll(); @@ -902,7 +902,7 @@ class ReplCopyAllAction extends EditorAction { run(accessor: ServicesAccessor, editor: ICodeEditor): void | Promise { const clipboardService = accessor.get(IClipboardService); - clipboardService.writeText(accessor.get(IPrivateReplService).getVisibleContent()); + return clipboardService.writeText(accessor.get(IPrivateReplService).getVisibleContent()); } } diff --git a/src/vs/workbench/contrib/debug/browser/variablesView.ts b/src/vs/workbench/contrib/debug/browser/variablesView.ts index b12ac70119b..6b51044d076 100644 --- a/src/vs/workbench/contrib/debug/browser/variablesView.ts +++ b/src/vs/workbench/contrib/debug/browser/variablesView.ts @@ -164,8 +164,7 @@ export class VariablesView extends ViewletPanel { actions.push(this.instantiationService.createInstance(CopyValueAction, CopyValueAction.ID, CopyValueAction.LABEL, variable, 'variables')); if (variable.evaluateName) { actions.push(new Action('debug.copyEvaluatePath', nls.localize('copyAsExpression', "Copy as Expression"), undefined, true, () => { - this.clipboardService.writeText(variable.evaluateName!); - return Promise.resolve(); + return this.clipboardService.writeText(variable.evaluateName!); })); actions.push(new Separator()); actions.push(new Action('debug.addToWatchExpressions', nls.localize('addToWatchExpressions', "Add to Watch"), undefined, true, () => { diff --git a/src/vs/workbench/contrib/extensions/electron-browser/extensionsActions.ts b/src/vs/workbench/contrib/extensions/electron-browser/extensionsActions.ts index fe4f91ede5c..7f600063a1b 100644 --- a/src/vs/workbench/contrib/extensions/electron-browser/extensionsActions.ts +++ b/src/vs/workbench/contrib/extensions/electron-browser/extensionsActions.ts @@ -857,8 +857,7 @@ export class ExtensionInfoAction extends ExtensionAction { const clipboardStr = `${name}\n${id}\n${description}\n${verision}\n${publisher}${link ? '\n' + link : ''}`; - this.clipboardService.writeText(clipboardStr); - return Promise.resolve(); + return this.clipboardService.writeText(clipboardStr); } } diff --git a/src/vs/workbench/contrib/files/browser/fileActions.ts b/src/vs/workbench/contrib/files/browser/fileActions.ts index bfe380ec78b..6e4cb97c935 100644 --- a/src/vs/workbench/contrib/files/browser/fileActions.ts +++ b/src/vs/workbench/contrib/files/browser/fileActions.ts @@ -796,10 +796,10 @@ class ClipboardContentProvider implements ITextModelContentProvider { @IModelService private readonly modelService: IModelService ) { } - provideTextContent(resource: URI): Promise { - const model = this.modelService.createModel(this.clipboardService.readText(), this.modeService.createByFilepathOrFirstLine(resource), resource); + async provideTextContent(resource: URI): Promise { + const model = this.modelService.createModel(await this.clipboardService.readText(), this.modeService.createByFilepathOrFirstLine(resource), resource); - return Promise.resolve(model); + return model; } } diff --git a/src/vs/workbench/contrib/files/browser/fileCommands.ts b/src/vs/workbench/contrib/files/browser/fileCommands.ts index 7155fc4dbbe..e94990d2390 100644 --- a/src/vs/workbench/contrib/files/browser/fileCommands.ts +++ b/src/vs/workbench/contrib/files/browser/fileCommands.ts @@ -436,13 +436,13 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ } }); -function resourcesToClipboard(resources: URI[], relative: boolean, clipboardService: IClipboardService, notificationService: INotificationService, labelService: ILabelService): void { +async function resourcesToClipboard(resources: URI[], relative: boolean, clipboardService: IClipboardService, notificationService: INotificationService, labelService: ILabelService): Promise { if (resources.length) { const lineDelimiter = isWindows ? '\r\n' : '\n'; const text = resources.map(resource => labelService.getUriLabel(resource, { relative, noPrefix: true })) .join(lineDelimiter); - clipboardService.writeText(text); + await clipboardService.writeText(text); } else { notificationService.info(nls.localize('openFileToCopy', "Open a file first to copy its path")); } @@ -456,9 +456,9 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_C }, id: COPY_PATH_COMMAND_ID, - handler: (accessor, resource: URI | object) => { + handler: async (accessor, resource: URI | object) => { const resources = getMultiSelectedResources(resource, accessor.get(IListService), accessor.get(IEditorService)); - resourcesToClipboard(resources, false, accessor.get(IClipboardService), accessor.get(INotificationService), accessor.get(ILabelService)); + await resourcesToClipboard(resources, false, accessor.get(IClipboardService), accessor.get(INotificationService), accessor.get(ILabelService)); } }); @@ -470,9 +470,9 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_C) }, id: COPY_RELATIVE_PATH_COMMAND_ID, - handler: (accessor, resource: URI | object) => { + handler: async (accessor, resource: URI | object) => { const resources = getMultiSelectedResources(resource, accessor.get(IListService), accessor.get(IEditorService)); - resourcesToClipboard(resources, true, accessor.get(IClipboardService), accessor.get(INotificationService), accessor.get(ILabelService)); + await resourcesToClipboard(resources, true, accessor.get(IClipboardService), accessor.get(INotificationService), accessor.get(ILabelService)); } }); @@ -481,12 +481,12 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ when: undefined, primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_P), id: 'workbench.action.files.copyPathOfActiveFile', - handler: (accessor) => { + handler: async (accessor) => { const editorService = accessor.get(IEditorService); const activeInput = editorService.activeEditor; const resource = activeInput ? activeInput.getResource() : null; const resources = resource ? [resource] : []; - resourcesToClipboard(resources, false, accessor.get(IClipboardService), accessor.get(INotificationService), accessor.get(ILabelService)); + await resourcesToClipboard(resources, false, accessor.get(IClipboardService), accessor.get(INotificationService), accessor.get(ILabelService)); } }); diff --git a/src/vs/workbench/contrib/markers/browser/markers.contribution.ts b/src/vs/workbench/contrib/markers/browser/markers.contribution.ts index f9c5325648a..08d95709864 100644 --- a/src/vs/workbench/contrib/markers/browser/markers.contribution.ts +++ b/src/vs/workbench/contrib/markers/browser/markers.contribution.ts @@ -109,8 +109,8 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(ShowProblemsPanelActio registerAction({ id: Constants.MARKER_COPY_ACTION_ID, title: { value: localize('copyMarker', "Copy"), original: 'Copy' }, - handler(accessor) { - copyMarker(accessor.get(IPanelService), accessor.get(IClipboardService)); + async handler(accessor) { + await copyMarker(accessor.get(IPanelService), accessor.get(IClipboardService)); }, menu: { menuId: MenuId.ProblemsPanelContext, @@ -127,8 +127,8 @@ registerAction({ registerAction({ id: Constants.MARKER_COPY_MESSAGE_ACTION_ID, title: { value: localize('copyMessage', "Copy Message"), original: 'Copy Message' }, - handler(accessor) { - copyMessage(accessor.get(IPanelService), accessor.get(IClipboardService)); + async handler(accessor) { + await copyMessage(accessor.get(IPanelService), accessor.get(IClipboardService)); }, menu: { menuId: MenuId.ProblemsPanelContext, @@ -139,8 +139,8 @@ registerAction({ registerAction({ id: Constants.RELATED_INFORMATION_COPY_MESSAGE_ACTION_ID, title: { value: localize('copyMessage', "Copy Message"), original: 'Copy Message' }, - handler(accessor) { - copyRelatedInformationMessage(accessor.get(IPanelService), accessor.get(IClipboardService)); + async handler(accessor) { + await copyRelatedInformationMessage(accessor.get(IPanelService), accessor.get(IClipboardService)); }, menu: { menuId: MenuId.ProblemsPanelContext, @@ -205,32 +205,32 @@ registerAction({ } }); -function copyMarker(panelService: IPanelService, clipboardService: IClipboardService) { +async function copyMarker(panelService: IPanelService, clipboardService: IClipboardService) { const activePanel = panelService.getActivePanel(); if (activePanel instanceof MarkersPanel) { const element = (activePanel).getFocusElement(); if (element instanceof Marker) { - clipboardService.writeText(`${element}`); + await clipboardService.writeText(`${element}`); } } } -function copyMessage(panelService: IPanelService, clipboardService: IClipboardService) { +async function copyMessage(panelService: IPanelService, clipboardService: IClipboardService) { const activePanel = panelService.getActivePanel(); if (activePanel instanceof MarkersPanel) { const element = (activePanel).getFocusElement(); if (element instanceof Marker) { - clipboardService.writeText(element.marker.message); + await clipboardService.writeText(element.marker.message); } } } -function copyRelatedInformationMessage(panelService: IPanelService, clipboardService: IClipboardService) { +async function copyRelatedInformationMessage(panelService: IPanelService, clipboardService: IClipboardService) { const activePanel = panelService.getActivePanel(); if (activePanel instanceof MarkersPanel) { const element = (activePanel).getFocusElement(); if (element instanceof RelatedInformation) { - clipboardService.writeText(element.raw.message); + await clipboardService.writeText(element.raw.message); } } } diff --git a/src/vs/workbench/contrib/performance/electron-browser/startupProfiler.ts b/src/vs/workbench/contrib/performance/electron-browser/startupProfiler.ts index 3509f0f2c51..ecfdd8e2ea0 100644 --- a/src/vs/workbench/contrib/performance/electron-browser/startupProfiler.ts +++ b/src/vs/workbench/contrib/performance/electron-browser/startupProfiler.ts @@ -103,21 +103,19 @@ export class StartupProfiler implements IWorkbenchContribution { }); } - private _createPerfIssue(files: string[]): Promise { - return this._textModelResolverService.createModelReference(PerfviewInput.Uri).then(ref => { + private async _createPerfIssue(files: string[]): Promise { + const ref = await this._textModelResolverService.createModelReference(PerfviewInput.Uri); + await this._clipboardService.writeText(ref.object.textEditorModel.getValue()); + ref.dispose(); - this._clipboardService.writeText(ref.object.textEditorModel.getValue()); - ref.dispose(); - - const body = ` + const body = ` 1. :warning: We have copied additional data to your clipboard. Make sure to **paste** here. :warning: 1. :warning: Make sure to **attach** these files from your *home*-directory: :warning:\n${files.map(file => `-\`${file}\``).join('\n')} `; - const baseUrl = product.reportIssueUrl; - const queryStringPrefix = baseUrl.indexOf('?') === -1 ? '?' : '&'; + const baseUrl = product.reportIssueUrl; + const queryStringPrefix = baseUrl.indexOf('?') === -1 ? '?' : '&'; - window.open(`${baseUrl}${queryStringPrefix}body=${encodeURIComponent(body)}`); - }); + window.open(`${baseUrl}${queryStringPrefix}body=${encodeURIComponent(body)}`); } } diff --git a/src/vs/workbench/contrib/preferences/browser/keybindingsEditor.ts b/src/vs/workbench/contrib/preferences/browser/keybindingsEditor.ts index d060784e1fa..b108f6696ba 100644 --- a/src/vs/workbench/contrib/preferences/browser/keybindingsEditor.ts +++ b/src/vs/workbench/contrib/preferences/browser/keybindingsEditor.ts @@ -248,7 +248,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor }); } - copyKeybinding(keybinding: IKeybindingItemEntry): void { + async copyKeybinding(keybinding: IKeybindingItemEntry): Promise { this.selectEntry(keybinding); this.reportKeybindingAction(KEYBINDINGS_EDITOR_COMMAND_COPY, keybinding.keybindingItem.command, keybinding.keybindingItem.keybinding); const userFriendlyKeybinding: IUserFriendlyKeybinding = { @@ -258,13 +258,13 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor if (keybinding.keybindingItem.when) { userFriendlyKeybinding.when = keybinding.keybindingItem.when; } - this.clipboardService.writeText(JSON.stringify(userFriendlyKeybinding, null, ' ')); + await this.clipboardService.writeText(JSON.stringify(userFriendlyKeybinding, null, ' ')); } - copyKeybindingCommand(keybinding: IKeybindingItemEntry): void { + async copyKeybindingCommand(keybinding: IKeybindingItemEntry): Promise { this.selectEntry(keybinding); this.reportKeybindingAction(KEYBINDINGS_EDITOR_COMMAND_COPY_COMMAND, keybinding.keybindingItem.command, keybinding.keybindingItem.keybinding); - this.clipboardService.writeText(keybinding.keybindingItem.command); + await this.clipboardService.writeText(keybinding.keybindingItem.command); } focusSearch(): void { diff --git a/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts b/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts index 89039aff9a2..fd207e9002b 100644 --- a/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts +++ b/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts @@ -332,10 +332,10 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ weight: KeybindingWeight.WorkbenchContrib, when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS), primary: KeyMod.CtrlCmd | KeyCode.KEY_C, - handler: (accessor, args: any) => { + handler: async (accessor, args: any) => { const control = accessor.get(IEditorService).activeControl as IKeybindingsEditor; if (control) { - control.copyKeybinding(control.activeKeybindingEntry!); + await control.copyKeybinding(control.activeKeybindingEntry!); } } }); @@ -345,10 +345,10 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ weight: KeybindingWeight.WorkbenchContrib, when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS), primary: 0, - handler: (accessor, args: any) => { + handler: async (accessor, args: any) => { const control = accessor.get(IEditorService).activeControl as IKeybindingsEditor; if (control) { - control.copyKeybindingCommand(control.activeKeybindingEntry!); + await control.copyKeybindingCommand(control.activeKeybindingEntry!); } } }); diff --git a/src/vs/workbench/contrib/preferences/browser/settingsTree.ts b/src/vs/workbench/contrib/preferences/browser/settingsTree.ts index 45db75ebd3b..68a62920e9a 100644 --- a/src/vs/workbench/contrib/preferences/browser/settingsTree.ts +++ b/src/vs/workbench/contrib/preferences/browser/settingsTree.ts @@ -1415,9 +1415,9 @@ class CopySettingIdAction extends Action { super(CopySettingIdAction.ID, CopySettingIdAction.LABEL); } - run(context: SettingsTreeSettingElement): Promise { + async run(context: SettingsTreeSettingElement): Promise { if (context) { - this.clipboardService.writeText(context.setting.key); + await this.clipboardService.writeText(context.setting.key); } return Promise.resolve(undefined); @@ -1434,10 +1434,10 @@ class CopySettingAsJSONAction extends Action { super(CopySettingAsJSONAction.ID, CopySettingAsJSONAction.LABEL); } - run(context: SettingsTreeSettingElement): Promise { + async run(context: SettingsTreeSettingElement): Promise { if (context) { const jsonResult = `"${context.setting.key}": ${JSON.stringify(context.value, undefined, ' ')}`; - this.clipboardService.writeText(jsonResult); + await this.clipboardService.writeText(jsonResult); } return Promise.resolve(undefined); diff --git a/src/vs/workbench/contrib/preferences/common/preferences.ts b/src/vs/workbench/contrib/preferences/common/preferences.ts index b0b5540271f..eb8c57ee939 100644 --- a/src/vs/workbench/contrib/preferences/common/preferences.ts +++ b/src/vs/workbench/contrib/preferences/common/preferences.ts @@ -62,8 +62,8 @@ export interface IKeybindingsEditor extends IEditor { updateKeybinding(keybindingEntry: IKeybindingItemEntry, key: string, when: string | undefined): Promise; removeKeybinding(keybindingEntry: IKeybindingItemEntry): Promise; resetKeybinding(keybindingEntry: IKeybindingItemEntry): Promise; - copyKeybinding(keybindingEntry: IKeybindingItemEntry): void; - copyKeybindingCommand(keybindingEntry: IKeybindingItemEntry): void; + copyKeybinding(keybindingEntry: IKeybindingItemEntry): Promise; + copyKeybindingCommand(keybindingEntry: IKeybindingItemEntry): Promise; showSimilarKeybindings(keybindingEntry: IKeybindingItemEntry): void; } diff --git a/src/vs/workbench/contrib/search/browser/searchActions.ts b/src/vs/workbench/contrib/search/browser/searchActions.ts index 68dc2624f5a..0d2d44cb5a1 100644 --- a/src/vs/workbench/contrib/search/browser/searchActions.ts +++ b/src/vs/workbench/contrib/search/browser/searchActions.ts @@ -671,11 +671,11 @@ function uriToClipboardString(resource: URI): string { return resource.scheme === Schemas.file ? normalize(normalizeDriveLetter(resource.fsPath)) : resource.toString(); } -export const copyPathCommand: ICommandHandler = (accessor, fileMatch: FileMatch | FolderMatch) => { +export const copyPathCommand: ICommandHandler = async (accessor, fileMatch: FileMatch | FolderMatch) => { const clipboardService = accessor.get(IClipboardService); const text = uriToClipboardString(fileMatch.resource()); - clipboardService.writeText(text); + await clipboardService.writeText(text); }; function matchToString(match: Match, indent = 0): string { @@ -736,7 +736,7 @@ function folderMatchToString(folderMatch: FolderMatch | BaseFolderMatch, maxMatc } const maxClipboardMatches = 1e4; -export const copyMatchCommand: ICommandHandler = (accessor, match: RenderableMatch) => { +export const copyMatchCommand: ICommandHandler = async (accessor, match: RenderableMatch) => { const clipboardService = accessor.get(IClipboardService); let text: string | undefined; @@ -749,7 +749,7 @@ export const copyMatchCommand: ICommandHandler = (accessor, match: RenderableMat } if (text) { - clipboardService.writeText(text); + await clipboardService.writeText(text); } }; @@ -768,7 +768,7 @@ function allFolderMatchesToString(folderMatches: Array { +export const copyAllCommand: ICommandHandler = async (accessor) => { const viewletService = accessor.get(IViewletService); const panelService = accessor.get(IPanelService); const clipboardService = accessor.get(IClipboardService); @@ -778,7 +778,7 @@ export const copyAllCommand: ICommandHandler = accessor => { const root = searchView.searchResult; const text = allFolderMatchesToString(root.folderMatches(), maxClipboardMatches); - clipboardService.writeText(text); + await clipboardService.writeText(text); } }; diff --git a/src/vs/workbench/contrib/terminal/browser/terminalActions.ts b/src/vs/workbench/contrib/terminal/browser/terminalActions.ts index 057a5df5631..d17e12cae98 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalActions.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalActions.ts @@ -159,10 +159,10 @@ export class CopyTerminalSelectionAction extends Action { super(id, label); } - public run(event?: any): Promise { + public async run(event?: any): Promise { const terminalInstance = this.terminalService.getActiveInstance(); if (terminalInstance) { - terminalInstance.copySelection(); + await terminalInstance.copySelection(); } return Promise.resolve(undefined); } diff --git a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts index 76c6127aa99..1f8229e39bc 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts @@ -713,9 +713,9 @@ export class TerminalInstance implements ITerminalInstance { return this._xterm && this._xterm.hasSelection(); } - public copySelection(): void { + public async copySelection(): Promise { if (this.hasSelection()) { - this._clipboardService.writeText(this._xterm.getSelection()); + await this._clipboardService.writeText(this._xterm.getSelection()); } else { this._notificationService.warn(nls.localize('terminal.integrated.copySelection.noSelection', 'The terminal has no selection to copy')); } diff --git a/src/vs/workbench/contrib/terminal/browser/terminalPanel.ts b/src/vs/workbench/contrib/terminal/browser/terminalPanel.ts index 01d79e0c592..c79e4eedcb0 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalPanel.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalPanel.ts @@ -203,7 +203,7 @@ export class TerminalPanel extends Panel { } private _attachEventListeners(): void { - this._register(dom.addDisposableListener(this._parentDomElement, 'mousedown', (event: MouseEvent) => { + this._register(dom.addDisposableListener(this._parentDomElement, 'mousedown', async (event: MouseEvent) => { if (this._terminalService.terminalInstances.length === 0) { return; } @@ -222,7 +222,7 @@ export class TerminalPanel extends Panel { return; } if (terminal.hasSelection()) { - terminal.copySelection(); + await terminal.copySelection(); terminal.clearSelection(); } else { terminal.paste(); @@ -240,7 +240,7 @@ export class TerminalPanel extends Panel { } } })); - this._register(dom.addDisposableListener(this._parentDomElement, 'mouseup', (event: MouseEvent) => { + this._register(dom.addDisposableListener(this._parentDomElement, 'mouseup', async (event: MouseEvent) => { if (this._configurationService.getValue('terminal.integrated.copyOnSelection')) { if (this._terminalService.terminalInstances.length === 0) { return; @@ -249,7 +249,7 @@ export class TerminalPanel extends Panel { if (event.which === 1) { const terminal = this._terminalService.getActiveInstance(); if (terminal && terminal.hasSelection()) { - terminal.copySelection(); + await terminal.copySelection(); } } } diff --git a/src/vs/workbench/contrib/terminal/common/terminal.ts b/src/vs/workbench/contrib/terminal/common/terminal.ts index 643d0aaeda2..53144ef0683 100644 --- a/src/vs/workbench/contrib/terminal/common/terminal.ts +++ b/src/vs/workbench/contrib/terminal/common/terminal.ts @@ -533,7 +533,7 @@ export interface ITerminalInstance { /** * Copies the terminal selection to the clipboard. */ - copySelection(): void; + copySelection(): Promise; /** * Current selection in the terminal. diff --git a/src/vs/workbench/workbench.web.main.ts b/src/vs/workbench/workbench.web.main.ts index f417d5c967d..23e94b90937 100644 --- a/src/vs/workbench/workbench.web.main.ts +++ b/src/vs/workbench/workbench.web.main.ts @@ -53,8 +53,8 @@ import { IMarkerService } from 'vs/platform/markers/common/markers'; import { MarkerService } from 'vs/platform/markers/common/markerService'; // import { IDownloadService } from 'vs/platform/download/common/download'; // import { DownloadService } from 'vs/platform/download/node/downloadService'; -// import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; -// import { ClipboardService } from 'vs/platform/clipboard/electron-browser/clipboardService'; +import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; +import { ClipboardService } from 'vs/platform/clipboard/browser/clipboardService'; import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyService'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IModelService } from 'vs/editor/common/services/modelService'; @@ -149,7 +149,7 @@ registerSingleton(IEditorWorkerService, EditorWorkerServiceImpl); registerSingleton(IMarkerDecorationsService, MarkerDecorationsService); registerSingleton(IMarkerService, MarkerService, true); // registerSingleton(IDownloadService, DownloadService, true); -// registerSingleton(IClipboardService, ClipboardService, true); +registerSingleton(IClipboardService, ClipboardService, true); registerSingleton(IContextKeyService, ContextKeyService); registerSingleton(IModelService, ModelServiceImpl, true); registerSingleton(ITextResourceConfigurationService, TextResourceConfigurationService); -- GitLab