fix(coding-agent): use native clipboard text copy on desktop closes #2347
This commit is contained in:
@@ -1988,7 +1988,7 @@ export class InteractiveMode {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (text === "/copy") {
|
if (text === "/copy") {
|
||||||
this.handleCopyCommand();
|
await this.handleCopyCommand();
|
||||||
this.editor.setText("");
|
this.editor.setText("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -4064,7 +4064,7 @@ export class InteractiveMode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleCopyCommand(): void {
|
private async handleCopyCommand(): Promise<void> {
|
||||||
const text = this.session.getLastAssistantText();
|
const text = this.session.getLastAssistantText();
|
||||||
if (!text) {
|
if (!text) {
|
||||||
this.showError("No agent messages to copy yet.");
|
this.showError("No agent messages to copy yet.");
|
||||||
@@ -4072,7 +4072,7 @@ export class InteractiveMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
copyToClipboard(text);
|
await copyToClipboard(text);
|
||||||
this.showStatus("Copied last agent message to clipboard");
|
this.showStatus("Copied last agent message to clipboard");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.showError(error instanceof Error ? error.message : String(error));
|
this.showError(error instanceof Error ? error.message : String(error));
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { createRequire } from "module";
|
import { createRequire } from "module";
|
||||||
|
|
||||||
export type ClipboardModule = {
|
export type ClipboardModule = {
|
||||||
|
setText: (text: string) => Promise<void>;
|
||||||
hasImage: () => boolean;
|
hasImage: () => boolean;
|
||||||
getImageBinary: () => Promise<Array<number>>;
|
getImageBinary: () => Promise<Array<number>>;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { execSync, spawn } from "child_process";
|
import { execSync, spawn } from "child_process";
|
||||||
import { platform } from "os";
|
import { platform } from "os";
|
||||||
import { isWaylandSession } from "./clipboard-image.js";
|
import { isWaylandSession } from "./clipboard-image.js";
|
||||||
|
import { clipboard } from "./clipboard-native.js";
|
||||||
|
|
||||||
type NativeClipboardExecOptions = {
|
type NativeClipboardExecOptions = {
|
||||||
input: string;
|
input: string;
|
||||||
@@ -16,11 +17,20 @@ function copyToX11Clipboard(options: NativeClipboardExecOptions): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function copyToClipboard(text: string): void {
|
export async function copyToClipboard(text: string): Promise<void> {
|
||||||
// Always emit OSC 52 - works over SSH/mosh, harmless locally
|
// Always emit OSC 52 - works over SSH/mosh, harmless locally
|
||||||
const encoded = Buffer.from(text).toString("base64");
|
const encoded = Buffer.from(text).toString("base64");
|
||||||
process.stdout.write(`\x1b]52;c;${encoded}\x07`);
|
process.stdout.write(`\x1b]52;c;${encoded}\x07`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (clipboard) {
|
||||||
|
await clipboard.setText(text);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Fall through to platform-specific clipboard tools.
|
||||||
|
}
|
||||||
|
|
||||||
// Also try native tools (best effort for local sessions)
|
// Also try native tools (best effort for local sessions)
|
||||||
const p = platform();
|
const p = platform();
|
||||||
const options: NativeClipboardExecOptions = { input: text, timeout: 5000, stdio: ["pipe", "ignore", "ignore"] };
|
const options: NativeClipboardExecOptions = { input: text, timeout: 5000, stdio: ["pipe", "ignore", "ignore"] };
|
||||||
|
|||||||
Reference in New Issue
Block a user