문제

Is it possible to get the current editor pane and edit the contents from an IntelliJ (IDEA) plugin?

I'd like to for example, select some text in the current editor and overwrite it with my own.

I've got this far;

Editor editor = FileEditorManager.getInstance(event.getProject()).getSelectedTextEditor();
VisualPosition position = editor.getCaretModel().getVisualPosition();
Document document = editor.getDocument();
document.insertString(position.column, Character.toString(text.charAt(offset)));

where event is AnActionEvent coming in from the AnAction class.

but it doesn't update the editor panel.

Any pointers much appreciated.

도움이 되었습니까?

해결책 2

Please see http://confluence.jetbrains.com/display/IDEADEV/IntelliJ+IDEA+Architectural+Overview for some general guidance.

It would be easier to answer your question if you specify your exact usecase.

다른 팁

Use document.replaceString(start,end,replaceSting) to replace text in editor.

For more information, see Working with Text:

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top