дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-08 19:02:17 +02:00
Copying files in the project view wrote only the file list to the OS clipboard, so pasting into an editor did nothing. The copy now also writes the newline-separated paths as text, which other applications can paste. WKWebView hides that text when file URLs are present and delivers a paste event with only Files, so the IDE editor and terminal still received nothing. A shared helper now reads the OS file list when a paste has files but no text, and inserts the paths. It covers Cmd+V and context-menu Paste in the editor, the terminal and embedded terminals. Markdown image paste runs first and keeps its behaviour. Verified on macOS. The Windows clipboard change was tested by the contributor at the clipboard level only. Refs #573 Co-authored-by: a-rookie-of-C-language <[email protected]>
30 рядки
1.2 KiB
TypeScript
30 рядки
1.2 KiB
TypeScript
import { call, commands, isTauri } from "./ipc";
|
|
|
|
/** WebKit exposes native file URLs as Files, hiding the pasteboard's text flavor. */
|
|
export async function readClipboardText(transfer?: DataTransfer | null): Promise<string> {
|
|
const text = transfer ? transfer.getData("text/plain") : ((await navigator.clipboard?.readText()) ?? "");
|
|
if (text || (transfer && !hasClipboardFiles(transfer)) || !isTauri()) return text;
|
|
try {
|
|
return (await call(commands.clipboardFileList())).join("\n");
|
|
} catch {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
function hasClipboardFiles(transfer: DataTransfer): boolean {
|
|
return !!transfer.files.length || Array.from(transfer.types).includes("Files");
|
|
}
|
|
|
|
/** Claim synchronously so the native handler cannot emit an empty paste while IPC runs. */
|
|
export function pasteClipboardFiles(event: ClipboardEvent, paste: (text: string) => void): boolean {
|
|
const transfer = event.clipboardData;
|
|
if (event.defaultPrevented || !transfer || transfer.getData("text/plain") || !hasClipboardFiles(transfer))
|
|
return false;
|
|
event.preventDefault();
|
|
event.stopImmediatePropagation();
|
|
void readClipboardText(transfer).then((text) => {
|
|
if (text) paste(text);
|
|
});
|
|
return true;
|
|
}
|