From 1147139fbb8174119528d71a99cb9a0688170999 Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Wed, 18 Dec 2024 12:27:49 -0800 Subject: [PATCH] fix: copy from context menu for chat references does not work (#236518) --- .../chatReferencesContentPart.ts | 30 +++++++++++++++++-- .../files/browser/fileActions.contribution.ts | 2 +- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/chatContentParts/chatReferencesContentPart.ts b/src/vs/workbench/contrib/chat/browser/chatContentParts/chatReferencesContentPart.ts index 3b71a48f0cc..a06c21d966b 100644 --- a/src/vs/workbench/contrib/chat/browser/chatContentParts/chatReferencesContentPart.ts +++ b/src/vs/workbench/contrib/chat/browser/chatContentParts/chatReferencesContentPart.ts @@ -19,7 +19,8 @@ import { localize, localize2 } from '../../../../../nls.js'; import { getFlatContextMenuActions } from '../../../../../platform/actions/browser/menuEntryActionViewItem.js'; import { MenuWorkbenchToolBar } from '../../../../../platform/actions/browser/toolbar.js'; import { Action2, IMenuService, MenuId, registerAction2 } from '../../../../../platform/actions/common/actions.js'; -import { IContextKeyService } from '../../../../../platform/contextkey/common/contextkey.js'; +import { IClipboardService } from '../../../../../platform/clipboard/common/clipboardService.js'; +import { ContextKeyExpr, IContextKeyService } from '../../../../../platform/contextkey/common/contextkey.js'; import { IContextMenuService } from '../../../../../platform/contextview/browser/contextView.js'; import { FileKind } from '../../../../../platform/files/common/files.js'; import { IInstantiationService, ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js'; @@ -476,7 +477,7 @@ registerAction2(class AddToChatAction extends Action2 { id: MenuId.ChatAttachmentsContext, group: 'chat', order: 1, - when: ExplorerFolderContext.negate(), + when: ContextKeyExpr.and(ResourceContextKey.IsFileSystemResource, ExplorerFolderContext.negate()), }] }); } @@ -498,4 +499,29 @@ registerAction2(class AddToChatAction extends Action2 { } }); +registerAction2(class OpenChatReferenceLinkAction extends Action2 { + + static readonly id = 'workbench.action.chat.copyLink'; + + constructor() { + super({ + id: OpenChatReferenceLinkAction.id, + title: { + ...localize2('copyLink', "Copy Link"), + }, + f1: false, + menu: [{ + id: MenuId.ChatAttachmentsContext, + group: 'chat', + order: 0, + when: ContextKeyExpr.or(ResourceContextKey.Scheme.isEqualTo(Schemas.http), ResourceContextKey.Scheme.isEqualTo(Schemas.https)), + }] + }); + } + + override async run(accessor: ServicesAccessor, resource: URI): Promise { + await accessor.get(IClipboardService).writeResources([resource]); + } +}); + //#endregion diff --git a/src/vs/workbench/contrib/files/browser/fileActions.contribution.ts b/src/vs/workbench/contrib/files/browser/fileActions.contribution.ts index 9da55d34ce3..be7dddf26ff 100644 --- a/src/vs/workbench/contrib/files/browser/fileActions.contribution.ts +++ b/src/vs/workbench/contrib/files/browser/fileActions.contribution.ts @@ -770,7 +770,7 @@ MenuRegistry.appendMenuItem(MenuId.ChatAttachmentsContext, { group: 'navigation', order: 10, command: openToSideCommand, - when: ContextKeyExpr.and(ResourceContextKey.HasResource, ExplorerFolderContext.toNegated()) + when: ContextKeyExpr.and(ResourceContextKey.IsFileSystemResource, ExplorerFolderContext.toNegated()) }); MenuRegistry.appendMenuItem(MenuId.ChatAttachmentsContext, {