forked from r.muellner/velum-raycast
Preserve rich formatting when restoring selected text
This commit is contained in:
27
src/rich-clipboard.ts
Normal file
27
src/rich-clipboard.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
// Raycast 2.0 Beta writes only plain text for Clipboard.copy({ html, text }).
|
||||
// Set both pasteboard types directly; environment variables avoid shell quoting.
|
||||
const RICH_COPY_SCRIPT = [
|
||||
"ObjC.import('AppKit');",
|
||||
"const env = $.NSProcessInfo.processInfo.environment;",
|
||||
"const html = env.objectForKey('VELUM_HTML');",
|
||||
"const text = env.objectForKey('VELUM_TEXT');",
|
||||
"const pb = $.NSPasteboard.generalPasteboard;",
|
||||
"pb.clearContents;",
|
||||
"pb.setStringForType(html, 'public.html');",
|
||||
"pb.setStringForType(text, 'public.utf8-plain-text');",
|
||||
].join("\n");
|
||||
|
||||
export async function copyRichText(html: string, text: string): Promise<void> {
|
||||
await execFileAsync(
|
||||
"osascript",
|
||||
["-l", "JavaScript", "-e", RICH_COPY_SCRIPT],
|
||||
{
|
||||
env: { ...process.env, VELUM_HTML: html, VELUM_TEXT: text },
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user