how to get the Editor from PsiElement?

hi ahh
i want the editor instance which is active now
DataManager didnot give but NULL
so i tried the following

Document document = PsiDocumentManager.getInstance(getElement().getProject()).getDocument(getElement().getContainingFile());
Editor editor= EditorFactory.getInstance().getEditors(document,getElement().getProject())[0];

but the editor array is 0 length and the document is not writable
by the way ,this is not accessed from an action so dataContext is not an option ;and obtaining it through DataManager result in nulls
thanks

1
5 comments
Avatar
Permanently deleted user

Hello joe,

j> i want the editor instance which is active now

FileEditorManager.getInstance().getSelectedTextEditor()

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


1
Avatar
Permanently deleted user

and if there is no selected text ?is it works also?

0
Avatar
Permanently deleted user

Hello joe,

j> and if there is no selected text ?is it works also?

It's not "get editor for selected text", it's "get text editor which is selected".

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Avatar
Permanently deleted user

ok,i may need some english lessons :) thanks

0

Since 201 the 

PsiEditorUtil.findEditor(psiElement);

seems to be the easiest solution to obtain Editor (require EDT)

0

Please sign in to leave a comment.