diff --git a/.changeset/long-zebras-yawn.md b/.changeset/long-zebras-yawn.md new file mode 100644 index 00000000..c38e0860 --- /dev/null +++ b/.changeset/long-zebras-yawn.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +copyToClipboard protobus migration diff --git a/proto/file.proto b/proto/file.proto index 81917000..c0779808 100644 --- a/proto/file.proto +++ b/proto/file.proto @@ -8,6 +8,9 @@ import "common.proto"; // Service for file-related operations service FileService { + // Copies text to clipboard + rpc copyToClipboard(StringRequest) returns (Empty); + // Opens a file in the editor rpc openFile(StringRequest) returns (Empty); diff --git a/src/core/controller/file/copyToClipboard.ts b/src/core/controller/file/copyToClipboard.ts new file mode 100644 index 00000000..156fa82c --- /dev/null +++ b/src/core/controller/file/copyToClipboard.ts @@ -0,0 +1,20 @@ +import * as vscode from "vscode" +import { Controller } from ".." +import { Empty, StringRequest } from "../../../shared/proto/common" + +/** + * Copies text to the system clipboard + * @param controller The controller instance + * @param request The request containing the text to copy + * @returns Empty response + */ +export async function copyToClipboard(controller: Controller, request: StringRequest): Promise { + try { + if (request.value) { + await vscode.env.clipboard.writeText(request.value) + } + } catch (error) { + console.error("Error copying to clipboard:", error) + } + return Empty.create() +} diff --git a/src/core/controller/index.ts b/src/core/controller/index.ts index ca7389ca..8bb36060 100644 --- a/src/core/controller/index.ts +++ b/src/core/controller/index.ts @@ -607,14 +607,6 @@ export class Controller { break } - case "copyToClipboard": { - try { - await vscode.env.clipboard.writeText(message.text || "") - } catch (error) { - console.error("Error copying to clipboard:", error) - } - break - } case "updateTerminalConnectionTimeout": { if (message.shellIntegrationTimeout !== undefined) { const timeout = message.shellIntegrationTimeout diff --git a/src/shared/WebviewMessage.ts b/src/shared/WebviewMessage.ts index 4d7ceaf8..3fdfe844 100644 --- a/src/shared/WebviewMessage.ts +++ b/src/shared/WebviewMessage.ts @@ -53,7 +53,6 @@ export interface WebviewMessage { | "toggleWindsurfRule" | "toggleWorkflow" | "deleteClineRule" - | "copyToClipboard" | "updateTerminalConnectionTimeout" | "setActiveQuote" diff --git a/src/shared/proto/file.ts b/src/shared/proto/file.ts index 644ab6d5..e24b38c9 100644 --- a/src/shared/proto/file.ts +++ b/src/shared/proto/file.ts @@ -906,6 +906,15 @@ export const FileServiceDefinition = { name: "FileService", fullName: "cline.FileService", methods: { + /** Copies text to clipboard */ + copyToClipboard: { + name: "copyToClipboard", + requestType: StringRequest, + requestStream: false, + responseType: Empty, + responseStream: false, + options: {}, + }, /** Opens a file in the editor */ openFile: { name: "openFile", diff --git a/src/standalone/server-setup.ts b/src/standalone/server-setup.ts index 769a06cc..f38e3aea 100644 --- a/src/standalone/server-setup.ts +++ b/src/standalone/server-setup.ts @@ -19,6 +19,7 @@ import { checkpointDiff } from "../core/controller/checkpoints/checkpointDiff" import { checkpointRestore } from "../core/controller/checkpoints/checkpointRestore" // File Service +import { copyToClipboard } from "../core/controller/file/copyToClipboard" import { openFile } from "../core/controller/file/openFile" import { openImage } from "../core/controller/file/openImage" import { deleteRuleFile } from "../core/controller/file/deleteRuleFile" @@ -100,6 +101,7 @@ export function addServices( // File Service server.addService(proto.cline.FileService.service, { + copyToClipboard: wrapper(copyToClipboard, controller), openFile: wrapper(openFile, controller), openImage: wrapper(openImage, controller), deleteRuleFile: wrapper(deleteRuleFile, controller), diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index 2206312c..b50f33b1 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -199,8 +199,14 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie } if (textToCopy !== null) { - vscode.postMessage({ type: "copyToClipboard", text: textToCopy }) - e.preventDefault() + try { + FileServiceClient.copyToClipboard({ value: textToCopy }).catch((err) => { + console.error("Error copying to clipboard:", err) + }) + e.preventDefault() + } catch (error) { + console.error("Error copying to clipboard:", error) + } } } }