Copy hisotry from LanguageConsole

已回答

Hey guys,

I've faced a problem that I can't solve myself. LanguageConsole in my project to execute command and it works pretty well except one thing: I can't copy colored text from history. Instead it's copied as a simple text.

There is no the issue with command/current editor - text is copied as expected but it doesn't work if I select and copy anything from history.

I've traced what I could and landed to CopyAsRichTextAction that contains the following line:

static boolean isRichCopyPossible(@NotNull Editor editor) {
// ideally, we'd also want to check for the presence of PsiFile (CopyHandler won't work without it), but it might be more expensive
return FileDocumentManager.getInstance().getFile(editor.getDocument()) != null;
}

and in LanguageConsoleImpl I can see that file is created for current editor only but historyViewer:

public LanguageConsoleImpl(@NotNull Helper helper) {
super(helper.project, GlobalSearchScope.allScope(helper.project), true, true);
myHelper = helper;
EditorFactory editorFactory = EditorFactory.getInstance();
myConsoleExecutionEditor = new ConsoleExecutionEditor(helper);
Disposer.register(this, myConsoleExecutionEditor);
myHistoryViewer = doCreateHistoryEditor();

so, the question is - is there any way to copy colored text from history editor?

评论操作 固定链接

Does using fake com.intellij.testFramework.LightVirtualFile with com.intellij.execution.console.LanguageConsoleImpl.Helper#Helper help?

0
评论操作 固定链接

Nope, unfortunately that doesn't work. LighVirtualFile and Helper works for current editor only. Even more, I've rebuild almost everything and finally set a file to historical document but it doesn't work anyway as historical document can't have language and base copy function doesn't work.

So, no solution for now, unfortunately, except create all from scretch and redefine copy function.

0

请先登录再写评论。