How to focus the Editor after insert text?

已回答

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
}
评论操作 固定链接
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
评论操作 固定链接

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

IdeFocusManager.getInstance(editor.project).requestFocus(editor.contentComponent, true)
1
评论操作 固定链接

Thank you, its working

0
评论操作 固定链接

Thanks for sharing the solution.

 

 

 

 

UPSers

0
评论操作 固定链接

wohh, i totally agree! A useful share

 

 

geometry dash

0

请先登录再写评论。