mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] extract function: keep selection range as narrow as possible
^KTIJ-29938 fixed GitOrigin-RevId: 5302707448930515842bf6e17b6e2f10f5e92fb0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7f21671ba2
commit
730f0bdcab
+8
@@ -0,0 +1,8 @@
|
||||
fun testFun(x: Any): Unit {
|
||||
println(x)
|
||||
extracted<caret>()
|
||||
}
|
||||
|
||||
private fun extracted() {
|
||||
println("that's something else")
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun testFun(x: Any): Unit {
|
||||
println(x)
|
||||
<selection>println("that's something else")</selection>
|
||||
}
|
||||
+2
-1
@@ -11,6 +11,7 @@ import com.intellij.openapi.keymap.KeymapUtil
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiComment
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.SmartPointerManager
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
@@ -61,7 +62,7 @@ interface AbstractInplaceExtractionHelper<KotlinType,
|
||||
val first = elements.first()
|
||||
val callTextRange =
|
||||
editor.document.createRangeMarker(
|
||||
max(rangeOf(PsiTreeUtil.skipWhitespacesAndCommentsBackward(first) ?: first).startOffset - 1, 0),
|
||||
max(rangeOf(PsiTreeUtil.skipSiblingsBackward(first, PsiComment::class.java) ?: first).startOffset - 1, 0),
|
||||
rangeOf(elements.last()).endOffset
|
||||
).apply {
|
||||
isGreedyToLeft = true
|
||||
|
||||
+4
@@ -50,6 +50,10 @@ class FirInplaceExtractFunctionTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testDontSkipWhitespacesBefore() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testStringTemplateWithNameConflict() {
|
||||
doTest(changedName = "substring")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user