Merge pull request #1587 from devxplay-forks/feat/raw-paste
feat(clipboard): add raw text paste functionality with keyboard shortcut
This commit is contained in:
@@ -154,3 +154,40 @@ export async function readImageFromClipboard(): Promise<ClipboardImage | null> {
|
||||
|
||||
return (await native.readImageFromClipboard()) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read plain text from the system clipboard.
|
||||
*/
|
||||
export async function readTextFromClipboard(): Promise<string> {
|
||||
try {
|
||||
const p = process.platform;
|
||||
if (p === "darwin") {
|
||||
return execSync("pbpaste", { encoding: "utf8", timeout: 2000 }).toString();
|
||||
}
|
||||
if (p === "win32") {
|
||||
return execSync('powershell.exe -NoProfile -Command "Get-Clipboard"', {
|
||||
encoding: "utf8",
|
||||
timeout: 2000,
|
||||
}).toString();
|
||||
}
|
||||
if (process.env.TERMUX_VERSION) {
|
||||
return execSync("termux-clipboard-get", { encoding: "utf8", timeout: 2000 }).toString();
|
||||
}
|
||||
const hasWaylandDisplay = Boolean(process.env.WAYLAND_DISPLAY);
|
||||
const hasX11Display = Boolean(process.env.DISPLAY);
|
||||
if (hasWaylandDisplay) {
|
||||
try {
|
||||
return execSync("wl-paste --type text/plain --no-newline", { encoding: "utf8", timeout: 2000 }).toString();
|
||||
} catch {
|
||||
if (hasX11Display) {
|
||||
return execSync("xclip -selection clipboard -o", { encoding: "utf8", timeout: 2000 }).toString();
|
||||
}
|
||||
}
|
||||
} else if (hasX11Display) {
|
||||
return execSync("xclip -selection clipboard -o", { encoding: "utf8", timeout: 2000 }).toString();
|
||||
}
|
||||
} catch (error) {
|
||||
logger.warn("clipboard: failed to read clipboard text", { error: String(error) });
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user