Embedding a Editor in a Tool Window

Answered

I want to embed a Editor in a Tool Window, to display snippets of (Java) code with syntax highlight, i.e. the main editor + a Tool Window with a code snippet that is syntax highlighted.

I have followed this example to create and add a FileEditor instance; https://intellij-support.jetbrains.com/hc/en-us/community/posts/206129029-Embedding-PsiAwareTextEditorImpl-in-a-tool-window-?input_string=Embedding%20a%20Editor%20in%20a%20Tool%20Window 

However I can figure out howto update the text displayed in the FileEditor. There seems to be no setFile() or setDocument() methods.

What am I doing wrong?

0
3 comments

Hi,

I suggest checking if the created FileEditor is an instance of TextEditor and using TextEditor.getEditor().getDocument().setText().

1

I suggest checking if the created FileEditor is an instance of TextEditor and using TextEditor.getEditor().getDocument().setText().

Perfect, worked like a charm. The object is a TextEditor and from that I can get set the text. 

fun setSuggestionText(suggestion: String) {
if (editor is TextEditor) {
val textEditor = editor as TextEditor

WriteCommandAction.runWriteCommandAction(
project,
) {
textEditor.editor.document.setText(suggestion)
}
}
}
0

Please sign in to leave a comment.