How to focus the Editor after insert text?

Answered

I have a function to manipulate the editor by clicking a button in a toolWindow.

But after clicking, i want to refocus the editor. Has somebody an idea?

fun manipulateForElement(editor:Editor){

val doc=editor.document
val caret=editor.caretModel.primaryCaret
val start=caret.selectionStart
val end=caret.selectionEnd

WriteCommandAction.runWriteCommandAction(editor.project) {
doc.replaceString(start, end,"test string")

}
caret.removeSelection()
caret.moveToOffset(start) // dont set the focus to the editor
}
1
5 comments

Ah, sorry about that - it is not available in the SDK. Please try with:

IdeFocusManager.getInstance(editor.project).requestFocus(editor.contentComponent, true)
1
Do you mean com.intellij.openapi.editor.ex.util.EditorUtil?

But this class has no method named "focusOnEditorForTyping".

Do you have an older version?

0

Thank you, its working

0

Thanks for sharing the solution.

 

 

 

 

UPSers

0

wohh, i totally agree! A useful share

 

 

geometry dash

0

Please sign in to leave a comment.