🐛 fix copy to clipboard in jetbrains
This commit is contained in:
parent
707590e414
commit
8add1a61cd
3 changed files with 20 additions and 3 deletions
|
|
@ -87,6 +87,7 @@ export type WebviewProtocol = Protocol &
|
|||
"stats/getTokensPerDay": [undefined, { day: string; tokens: number }[]];
|
||||
"stats/getTokensPerModel": [undefined, { model: string; tokens: number }[]];
|
||||
insertAtCursor: [{ text: string }, void];
|
||||
copyText: [{ text: string }, void];
|
||||
"jetbrains/editorInsetHeight": [{ height: number }, void];
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ import com.intellij.openapi.wm.WindowManager
|
|||
import com.intellij.testFramework.LightVirtualFile
|
||||
import com.intellij.ui.awt.RelativePoint
|
||||
import kotlinx.coroutines.*
|
||||
import java.awt.Toolkit
|
||||
import java.awt.datatransfer.StringSelection
|
||||
import java.io.*
|
||||
import java.net.NetworkInterface
|
||||
import java.nio.charset.Charset
|
||||
|
|
@ -189,6 +191,14 @@ class IdeProtocolClient (
|
|||
respond(uniqueId())
|
||||
}
|
||||
|
||||
"copyText" -> {
|
||||
val data = data as Map<String, Any>
|
||||
val text = data["text"] as String
|
||||
val clipboard = Toolkit.getDefaultToolkit().systemClipboard
|
||||
val stringSelection = StringSelection(text)
|
||||
clipboard.setContents(stringSelection, stringSelection)
|
||||
}
|
||||
|
||||
"showDiff" -> {
|
||||
val data = data as Map<String, Any>
|
||||
diffManager.showDiff(
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { CheckIcon, ClipboardIcon } from "@heroicons/react/24/outline";
|
||||
import { useState } from "react";
|
||||
import { ideRequest, isJetBrains } from "../../util/ide";
|
||||
import HeaderButtonWithText from "../HeaderButtonWithText";
|
||||
|
||||
interface CopyButtonProps {
|
||||
|
|
@ -15,9 +16,14 @@ export function CopyButton(props: CopyButtonProps) {
|
|||
<HeaderButtonWithText
|
||||
text={copied ? "Copied!" : "Copy"}
|
||||
onClick={(e) => {
|
||||
navigator.clipboard.writeText(
|
||||
typeof props.text === "string" ? props.text : props.text(),
|
||||
);
|
||||
const text =
|
||||
typeof props.text === "string" ? props.text : props.text();
|
||||
if (isJetBrains()) {
|
||||
ideRequest("copyText", { text });
|
||||
} else {
|
||||
navigator.clipboard.writeText(text);
|
||||
}
|
||||
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
}}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue