forked from r.muellner/velum-raycast
Preserve rich formatting when restoring selected text
This commit is contained in:
@@ -13,8 +13,6 @@ import {
|
||||
Toast,
|
||||
useNavigation,
|
||||
} from "@raycast/api";
|
||||
import { execFile } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
import { marked } from "marked";
|
||||
import { type ReactNode, useEffect, useRef, useState } from "react";
|
||||
import type { Creativity } from "./ai";
|
||||
@@ -22,6 +20,7 @@ import { getPreferences } from "./preferences";
|
||||
import type { VelumSession } from "./types";
|
||||
import { markdownCodeBlock, mappingDetailTable, sessionSubtitle } from "./ui";
|
||||
import { localDepseudonymize } from "./velum";
|
||||
import { copyRichText } from "./rich-clipboard";
|
||||
|
||||
export async function maybeCloseRaycast(): Promise<void> {
|
||||
if (getPreferences().closeAfterAction) {
|
||||
@@ -29,33 +28,6 @@ export async function maybeCloseRaycast(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
// Raycast 2.0 Beta's Clipboard.copy with { html, text } only writes plain text
|
||||
// to the system pasteboard. We bypass it via osascript / JXA, which sets both
|
||||
// the HTML and plain-text pasteboard types directly on NSPasteboard. Content
|
||||
// is passed via environment variables to avoid shell-quoting hazards.
|
||||
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 },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export type AiCommandLabels = {
|
||||
pageHeading: string;
|
||||
runningLabel: string;
|
||||
|
||||
Reference in New Issue
Block a user