CreateCallableFromUsageFix always calls openInEditor to force proper editor and focus
This commit is contained in:
+8
-14
@@ -17,9 +17,9 @@
|
||||
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
||||
|
||||
import com.intellij.codeInsight.intention.LowPriorityAction
|
||||
import com.intellij.codeInsight.navigation.NavigationUtil
|
||||
import com.intellij.ide.util.EditorHelper
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiElement
|
||||
@@ -177,20 +177,14 @@ abstract class CreateCallableFromUsageFixBase<E : KtElement>(
|
||||
}
|
||||
|
||||
override fun invokeImpl(project: Project, editor: Editor?, file: PsiFile) {
|
||||
if (editor == null) return
|
||||
|
||||
val element = element ?: return
|
||||
val callableInfo = callableInfos.first()
|
||||
|
||||
val fileForBuilder: KtFile
|
||||
val editorForBuilder: Editor
|
||||
if (file is KtFile) {
|
||||
fileForBuilder = file
|
||||
editorForBuilder = editor
|
||||
} else {
|
||||
fileForBuilder = element.containingKtFile
|
||||
EditorHelper.openInEditor(element)
|
||||
editorForBuilder = FileEditorManager.getInstance(project).selectedTextEditor!!
|
||||
val fileForBuilder = element.containingKtFile
|
||||
|
||||
val editorForBuilder = EditorHelper.openInEditor(element)
|
||||
if (editorForBuilder != editor) {
|
||||
NavigationUtil.activateFileWithPsiElement(element)
|
||||
}
|
||||
|
||||
val callableBuilder =
|
||||
@@ -220,7 +214,7 @@ abstract class CreateCallableFromUsageFixBase<E : KtElement>(
|
||||
val containers = receiverTypeCandidates
|
||||
.mapNotNull { candidate -> getDeclarationIfApplicable(project, candidate)?.let { candidate to it } }
|
||||
|
||||
chooseContainerElementIfNecessary(containers, editor, popupTitle, false, { it.second }) {
|
||||
chooseContainerElementIfNecessary(containers, editorForBuilder, popupTitle, false, { it.second }) {
|
||||
runBuilder(CallablePlacement.WithReceiver(it.first))
|
||||
}
|
||||
} else {
|
||||
@@ -228,7 +222,7 @@ abstract class CreateCallableFromUsageFixBase<E : KtElement>(
|
||||
"No receiver type candidates: ${element.text} in ${file.text}"
|
||||
}
|
||||
|
||||
chooseContainerElementIfNecessary(callableInfo.possibleContainers, editor, popupTitle, true, { it }) {
|
||||
chooseContainerElementIfNecessary(callableInfo.possibleContainers, editorForBuilder, popupTitle, true, { it }) {
|
||||
val container = if (it is KtClassBody) it.parent as KtClassOrObject else it
|
||||
runBuilder(CallablePlacement.NoReceiver(container))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user