From 5782a99eb63a49a19fd0bb14b47795be7ee43821 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Fri, 28 Apr 2023 12:44:57 +0200 Subject: [PATCH] add a method to copy text to the clipboard GitOrigin-RevId: ba759796658495aed214c048cc2002ab6c052727 --- platform/lang-impl/src/com/intellij/ide/CopyPasteUtil.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/ide/CopyPasteUtil.java b/platform/lang-impl/src/com/intellij/ide/CopyPasteUtil.java index f8a28971261f..27a730f3459e 100644 --- a/platform/lang-impl/src/com/intellij/ide/CopyPasteUtil.java +++ b/platform/lang-impl/src/com/intellij/ide/CopyPasteUtil.java @@ -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;