提交 305d5be1 编写于 作者: S SteVen Batten 提交者: Benjamin Pasero

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
上级 9f7ba699
......@@ -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<string> { return readTextResult; }
readTextSync(): any { return readTextResult; }
_throw = () => { throw new Error(); };
writeText = this._throw;
......
/*---------------------------------------------------------------------------------------------
* 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<IClipboardService>;
private _internalResourcesClipboard: URI[] | undefined;
async writeText(text: string, type?: string): Promise<void> {
return navigator.clipboard.writeText(text);
}
async readText(type?: string): Promise<string> {
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
......@@ -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<void>;
/**
* Reads the content of the clipboard in plain text
*/
readText(type?: string): string;
readText(type?: string): Promise<string>;
readTextSync(): string | undefined;
......
......@@ -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<void> {
clipboard.writeText(text, type);
}
readText(type?: 'selection' | 'clipboard'): string {
async readText(type?: 'selection' | 'clipboard'): Promise<string> {
return clipboard.readText(type);
}
......
......@@ -20,11 +20,10 @@ export class MainThreadClipboard implements MainThreadClipboardShape {
}
$readText(): Promise<string> {
return Promise.resolve(this._clipboardService.readText());
return this._clipboardService.readText();
}
$writeText(value: string): Promise<void> {
this._clipboardService.writeText(value);
return Promise.resolve();
return this._clipboardService.writeText(value);
}
}
......@@ -145,9 +145,7 @@ export class CopyNotificationMessageAction extends Action {
}
run(notification: INotificationViewItem): Promise<any> {
this.clipboardService.writeText(notification.message.raw);
return Promise.resolve();
return this.clipboardService.writeText(notification.message.raw);
}
}
......
......@@ -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 {
......
......@@ -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);
}
}
......@@ -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));
}
});
......
......@@ -472,16 +472,16 @@ export class Repl extends Panel implements IPrivateReplService, IHistoryNavigati
private onContextMenu(e: ITreeContextMenuEvent<IReplElement>): 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<void> {
const clipboardService = accessor.get(IClipboardService);
clipboardService.writeText(accessor.get(IPrivateReplService).getVisibleContent());
return clipboardService.writeText(accessor.get(IPrivateReplService).getVisibleContent());
}
}
......
......@@ -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, () => {
......
......@@ -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);
}
}
......
......@@ -796,10 +796,10 @@ class ClipboardContentProvider implements ITextModelContentProvider {
@IModelService private readonly modelService: IModelService
) { }
provideTextContent(resource: URI): Promise<ITextModel> {
const model = this.modelService.createModel(this.clipboardService.readText(), this.modeService.createByFilepathOrFirstLine(resource), resource);
async provideTextContent(resource: URI): Promise<ITextModel> {
const model = this.modelService.createModel(await this.clipboardService.readText(), this.modeService.createByFilepathOrFirstLine(resource), resource);
return Promise.resolve(model);
return model;
}
}
......
......@@ -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<void> {
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));
}
});
......
......@@ -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 = (<MarkersPanel>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 = (<MarkersPanel>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 = (<MarkersPanel>activePanel).getFocusElement();
if (element instanceof RelatedInformation) {
clipboardService.writeText(element.raw.message);
await clipboardService.writeText(element.raw.message);
}
}
}
......
......@@ -103,10 +103,9 @@ export class StartupProfiler implements IWorkbenchContribution {
});
}
private _createPerfIssue(files: string[]): Promise<void> {
return this._textModelResolverService.createModelReference(PerfviewInput.Uri).then(ref => {
this._clipboardService.writeText(ref.object.textEditorModel.getValue());
private async _createPerfIssue(files: string[]): Promise<void> {
const ref = await this._textModelResolverService.createModelReference(PerfviewInput.Uri);
await this._clipboardService.writeText(ref.object.textEditorModel.getValue());
ref.dispose();
const body = `
......@@ -118,6 +117,5 @@ export class StartupProfiler implements IWorkbenchContribution {
const queryStringPrefix = baseUrl.indexOf('?') === -1 ? '?' : '&';
window.open(`${baseUrl}${queryStringPrefix}body=${encodeURIComponent(body)}`);
});
}
}
......@@ -248,7 +248,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
});
}
copyKeybinding(keybinding: IKeybindingItemEntry): void {
async copyKeybinding(keybinding: IKeybindingItemEntry): Promise<void> {
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<void> {
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 {
......
......@@ -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!);
}
}
});
......
......@@ -1415,9 +1415,9 @@ class CopySettingIdAction extends Action {
super(CopySettingIdAction.ID, CopySettingIdAction.LABEL);
}
run(context: SettingsTreeSettingElement): Promise<void> {
async run(context: SettingsTreeSettingElement): Promise<void> {
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<void> {
async run(context: SettingsTreeSettingElement): Promise<void> {
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);
......
......@@ -62,8 +62,8 @@ export interface IKeybindingsEditor extends IEditor {
updateKeybinding(keybindingEntry: IKeybindingItemEntry, key: string, when: string | undefined): Promise<any>;
removeKeybinding(keybindingEntry: IKeybindingItemEntry): Promise<any>;
resetKeybinding(keybindingEntry: IKeybindingItemEntry): Promise<any>;
copyKeybinding(keybindingEntry: IKeybindingItemEntry): void;
copyKeybindingCommand(keybindingEntry: IKeybindingItemEntry): void;
copyKeybinding(keybindingEntry: IKeybindingItemEntry): Promise<void>;
copyKeybindingCommand(keybindingEntry: IKeybindingItemEntry): Promise<void>;
showSimilarKeybindings(keybindingEntry: IKeybindingItemEntry): void;
}
......
......@@ -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<FolderMatch | BaseFolderM
return folderResults.join(lineDelimiter + lineDelimiter);
}
export const copyAllCommand: ICommandHandler = accessor => {
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);
}
};
......
......@@ -159,10 +159,10 @@ export class CopyTerminalSelectionAction extends Action {
super(id, label);
}
public run(event?: any): Promise<any> {
public async run(event?: any): Promise<any> {
const terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.copySelection();
await terminalInstance.copySelection();
}
return Promise.resolve(undefined);
}
......
......@@ -713,9 +713,9 @@ export class TerminalInstance implements ITerminalInstance {
return this._xterm && this._xterm.hasSelection();
}
public copySelection(): void {
public async copySelection(): Promise<void> {
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'));
}
......
......@@ -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();
}
}
}
......
......@@ -533,7 +533,7 @@ export interface ITerminalInstance {
/**
* Copies the terminal selection to the clipboard.
*/
copySelection(): void;
copySelection(): Promise<void>;
/**
* Current selection in the terminal.
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册