Extend Selection: don't select lambda parameters if lambda is multiple lines (#2586)

#KT-29364  Fixed
This commit is contained in:
Toshiaki Kameyama
2020-06-11 18:20:32 +09:00
committed by GitHub
parent 232be94738
commit 46907f861a
19 changed files with 141 additions and 0 deletions
@@ -23,6 +23,7 @@ import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.impl.source.tree.LeafPsiElement
import org.jetbrains.kotlin.idea.refactoring.getLineNumber
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.siblings
@@ -44,6 +45,7 @@ class KotlinStatementGroupSelectioner : ExtendWordSelectionHandlerBase() {
.firstOrNull {
// find preceding '{' or blank line
it is LeafPsiElement && it.elementType == KtTokens.LBRACE || it is PsiWhiteSpace && it.getText()!!.count { it == '\n' } > 1
|| (it is LeafPsiElement && it.elementType == KtTokens.ARROW && e.getLineNumber() != it.getLineNumber())
}
?.siblings(forward = true, withItself = false)
?.dropWhile { it is PsiWhiteSpace } // and take first non-whitespace element after it
@@ -0,0 +1,5 @@
fun foo(f: (Int) -> Int) {}
fun test() {
foo { it -> <caret>it + 1 }
}
@@ -0,0 +1,5 @@
fun foo(f: (Int) -> Int) {}
fun test() {
foo { it -> <caret><selection>it</selection> + 1 }
}
@@ -0,0 +1,5 @@
fun foo(f: (Int) -> Int) {}
fun test() {
foo { it -> <caret><selection>it + 1</selection> }
}
@@ -0,0 +1,5 @@
fun foo(f: (Int) -> Int) {}
fun test() {
foo { <selection>it -> <caret>it + 1</selection> }
}
@@ -0,0 +1,5 @@
fun foo(f: (Int) -> Int) {}
fun test() {
foo <selection>{ it -> <caret>it + 1 }</selection>
}
@@ -0,0 +1,9 @@
fun foo(f: (Int) -> Int) {}
fun test() {
foo { it ->
<caret>it + 1
it + 1
}
}
@@ -0,0 +1,9 @@
fun foo(f: (Int) -> Int) {}
fun test() {
foo { it ->
<caret><selection>it</selection> + 1
it + 1
}
}
@@ -0,0 +1,9 @@
fun foo(f: (Int) -> Int) {}
fun test() {
foo { it ->
<caret><selection>it + 1</selection>
it + 1
}
}
@@ -0,0 +1,9 @@
fun foo(f: (Int) -> Int) {}
fun test() {
foo { it ->
<selection> <caret>it + 1
</selection>
it + 1
}
}
@@ -0,0 +1,9 @@
fun foo(f: (Int) -> Int) {}
fun test() {
foo { it ->
<selection> <caret>it + 1
it + 1
</selection> }
}
@@ -0,0 +1,9 @@
fun foo(f: (Int) -> Int) {}
fun test() {
foo <selection>{ it ->
<caret>it + 1
it + 1
}</selection>
}
@@ -0,0 +1,9 @@
fun foo(f: (Int) -> Int) {}
fun test() {
foo { it ->
it + 1
<caret>it + 1
}
}
@@ -0,0 +1,9 @@
fun foo(f: (Int) -> Int) {}
fun test() {
foo { it ->
it + 1
<caret><selection>it</selection> + 1
}
}
@@ -0,0 +1,9 @@
fun foo(f: (Int) -> Int) {}
fun test() {
foo { it ->
it + 1
<caret><selection>it + 1</selection>
}
}
@@ -0,0 +1,9 @@
fun foo(f: (Int) -> Int) {}
fun test() {
foo { it ->
it + 1
<selection> <caret>it + 1
</selection> }
}
@@ -0,0 +1,9 @@
fun foo(f: (Int) -> Int) {}
fun test() {
foo { it ->
<selection> it + 1
<caret>it + 1
</selection> }
}
@@ -0,0 +1,9 @@
fun foo(f: (Int) -> Int) {}
fun test() {
foo <selection>{ it ->
it + 1
<caret>it + 1
}</selection>
}
@@ -39,6 +39,12 @@ public class WordSelectionTest extends KotlinLightCodeInsightFixtureTestCase {
public void testValueParametersInLambda() { doTest(); }
public void testValueParametersInLambda2() { doTest(); }
public void testValueParametersInLambda3() { doTest(); }
public void testValueParametersInLambda4() { doTest(); }
public void testDocComment() { doTest(); }
public void testDocCommentOneLine() { doTest(); }