IJ-CR-168246: Review fixes

GitOrigin-RevId: a6a42bd3cee9554e353857f659454be68d8beee1
This commit is contained in:
Ilya Muradyan
2025-07-11 16:54:06 +00:00
committed by intellij-monorepo-bot
parent 902e84fce4
commit ccc3a2d45f
3 changed files with 6 additions and 20 deletions
@@ -343,7 +343,7 @@ public class ShowIntentionActionsHandler implements CodeInsightActionHandler {
PsiFile psiFile = pair.first;
Editor editor = pair.second;
if (fixOffset != -1) {
if (maybeInjectedFixOffset != -1) {
Document document = editor.getDocument();
if (document instanceof DocumentWindow) {
maybeInjectedFixOffset = ((DocumentWindow)document).hostToInjected(fixOffset);
@@ -131,15 +131,10 @@ class PsiTargetNavigator<T: PsiElement>(val supplier: Supplier<Collection<T>>) {
ItemWithPresentation(SmartPointerManager.createPointer(it),
presentationProvider.getPresentation(it))
}
val selected = if (selection == null){
val selected = if (selection == null) {
null
} else {
val index = elements.indexOf(selection)
if (index == -1) {
null
} else {
list[index]
}
list.getOrNull(elements.indexOf(selection))
}
Pair(list, selected)
}
@@ -32,7 +32,9 @@ object CreateFromUsageUtil {
val psiFactory = KtPsiFactory(container.project)
val newLine = psiFactory.createNewLine()
val actualContainer = (container as? KtClassOrObject)?.getOrCreateBody() ?: getActualContainerForScript(container)
val actualContainer = (container as? KtClassOrObject)?.getOrCreateBody()
?: (container as? KtFile)?.script?.blockExpression
?: container
val declarationInPlace = when {
declaration is KtPrimaryConstructor -> {
@@ -236,15 +238,4 @@ object CreateFromUsageUtil {
actualContainer.addAfter(declaration, sibling)
} as D
}
/**
* In scripts, no elements should exist outside the main block expression
*/
private fun getActualContainerForScript(container: PsiElement): PsiElement {
return if ((container as? KtFile)?.isScript() == true) {
container.script?.blockExpression ?: container
} else {
container
}
}
}