Chaning Document from FileEditor

Hi,

How do I manipulate Document from FileEditor? I implemented my FileEditor, which changes Document for a selected virtual file. When doing things like Document.replaceString, I have to call it from EditorWriteAction, correct?

To call it, I need to pass an "Editor" implementation. However, I don't have an associated "Editor" implementation for the virtual file because I am using my own "FileEditor".

Do I have to open an TextEditor for that purpose? Or are there any other ways to do it?

Thanks in advance.

-


Kenji

3 comments

Hi,

May be something like this:
EditorFactory editorFactory = EditorFactory.getInstance();
editor = editorFactory.createEditor(document, myProject);

Wil help

TIA,
Dmitry

0

Thanks, Dmitry

Alternatively, I could put the code that makes changes to Document object inside CommandProcessor.executeCommand() and Application.runWriteAction(). It would work sucessfully without getting an exception.

However, the changes made by the code wouldn't be undoable would it?

I will try creating an editor using the factory and execute the EditorWriteAction and see what happens...

Thank you.

---
Kenji


0

Hi,
It will work.
Changes will undoable until you make it transparent to undo, there are some way to do it I don't remember it exactly but it something like runUndoTransparentAction().

But question was how to get editor ;)

TIA,
Dmitry

0

Please sign in to leave a comment.