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
}
Please sign in to leave a comment.
Ah, sorry about that - it is not available in the SDK. Please try with:
Do you mean com.intellij.openapi.editor.ex.util.EditorUtil?
But this class has no method named "focusOnEditorForTyping".
Do you have an older version?
Thank you, its working
Thanks for sharing the solution.
UPSers
wohh, i totally agree! A useful share
geometry dash