[kotlin] Extract variable: suggest expression to the left of the dot if caret is right before it

^KTIJ-31458 Fixed

GitOrigin-RevId: aa114eb34a87ef07bf05c9f23d270a13fee76a27
This commit is contained in:
Andrey Cherkasov
2024-10-02 23:35:45 +00:00
committed by intellij-monorepo-bot
parent 070d7ebb92
commit 7f4d4d3234
3 changed files with 20 additions and 0 deletions
@@ -50,6 +50,11 @@ public class SmartSelectionTestGenerated extends AbstractSmartSelectionTest {
runTest("testData/smartSelection/beforeComment.kt");
}
@TestMetadata("beforeDot.kt")
public void testBeforeDot() throws Exception {
runTest("testData/smartSelection/beforeDot.kt");
}
@TestMetadata("beforeKDocComment.kt")
public void testBeforeKDocComment() throws Exception {
runTest("testData/smartSelection/beforeKDocComment.kt");
@@ -0,0 +1,13 @@
class Foo {
val foo: Foo = this
val bar: Foo = this
fun f(f: Foo) {
val foo1 = f.foo<caret>.bar
}
}
/*
f.foo
f.foo.bar
*/
@@ -12,6 +12,7 @@ import com.intellij.openapi.ui.popup.JBPopupListener
import com.intellij.openapi.ui.popup.LightweightWindowEvent
import com.intellij.platform.backend.presentation.TargetPresentation
import com.intellij.psi.*
import com.intellij.psi.impl.source.tree.LeafPsiElement
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.concurrency.AppExecutorUtil
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
@@ -118,6 +119,7 @@ fun getSmartSelectSuggestions(
|| isOriginalOffset && element?.node?.elementType == KtTokens.RPAR
|| element is PsiComment
|| element?.getStrictParentOfType<KDoc>() != null
|| element is LeafPsiElement && element.elementType == KtTokens.DOT
) return getSmartSelectSuggestions(file, offset - 1, elementKind, isOriginalOffset = false)
val elements = ArrayList<KtElement>()