add a method to copy text to the clipboard

GitOrigin-RevId: ba759796658495aed214c048cc2002ab6c052727
This commit is contained in:
Konstantin Bulenkov
2023-04-28 12:29:15 +00:00
committed by intellij-monorepo-bot
parent 1b9a105d48
commit 5782a99eb6
@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide;
@@ -8,6 +8,7 @@ import com.intellij.openapi.ide.CopyPasteManager;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.util.function.Consumer;
@@ -16,6 +17,10 @@ import static com.intellij.openapi.application.ApplicationManager.getApplication
public final class CopyPasteUtil {
private CopyPasteUtil() { }
public static void copyTextToClipboard(@NotNull String text) {
CopyPasteManager.getInstance().setContents(new StringSelection(text));
}
public static PsiElement[] getElementsInTransferable(Transferable t) {
final PsiElement[] elts = PsiCopyPasteManager.getElements(t);
return elts != null ? elts : PsiElement.EMPTY_ARRAY;