Need help with choosing the right text editor component


In my plugin I need to have an editor component similar to the default one in IntelliJ. What I need is syntax highlighting, line numbers and support for different types, e.g. XML, JSON, etc. I will not have any virtual files or psi files associated with this editor component, i.e. I will only let user type or paste the text into that editor - so I cannot use the existing PsiAwareTextEditorImpl. I tried to use EditorTextField, e.g.:

EditorTextField textField = new EditorTextField();

but it looks just like plain text area, no formatting, no scrolling, no line numbers. So I'm wondering if there's anything better out there?


1 comment

Nevermind, I found the answer here in one of the previous posts. Now my code works just fine. For those who are interested, this is what my solution looks like:


Language language = null;
Collection<Language> langs = Language.findInstancesByMimeType(dataType.getText());
if (langs.isEmpty()) {
language = PlainTextLanguage.INSTANCE;
} else {
language = langs.iterator().next();//Pick first one

PsiFile f = PsiFileFactory.getInstance(getProject()).createFileFromText(language,"");

Editor editor = EditorFactory.getInstance().createEditor(f.getViewProvider().getDocument(), getProject(), language.getAssociatedFileType(), false);



Please sign in to leave a comment.