Extend Selection: whole literal with braces is selected after parameters (KT-13420)
#KT-13420 Fixed
This commit is contained in:
committed by
Nikolay Krasko
parent
05269cea2f
commit
5aa0b7d2aa
+4
-6
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
|
|||||||
*/
|
*/
|
||||||
class KotlinStatementGroupSelectioner : ExtendWordSelectionHandlerBase() {
|
class KotlinStatementGroupSelectioner : ExtendWordSelectionHandlerBase() {
|
||||||
override fun canSelect(e: PsiElement): Boolean {
|
override fun canSelect(e: PsiElement): Boolean {
|
||||||
if (e !is KtExpression && e !is KtWhenEntry && e !is PsiComment) return false
|
if (e !is KtExpression && e !is KtWhenEntry && e !is KtParameterList && e !is PsiComment) return false
|
||||||
val parent = e.parent
|
val parent = e.parent
|
||||||
return parent is KtBlockExpression || parent is KtWhenExpression || parent is KtFunctionLiteral
|
return parent is KtBlockExpression || parent is KtWhenExpression || parent is KtFunctionLiteral
|
||||||
}
|
}
|
||||||
@@ -43,8 +43,7 @@ class KotlinStatementGroupSelectioner : ExtendWordSelectionHandlerBase() {
|
|||||||
val startElement = e.siblings(forward = false, withItself = false)
|
val startElement = e.siblings(forward = false, withItself = false)
|
||||||
.firstOrNull {
|
.firstOrNull {
|
||||||
// find preceding '{' or blank line
|
// find preceding '{' or blank line
|
||||||
it is LeafPsiElement && it.elementType == KtTokens.LBRACE ||
|
it is LeafPsiElement && it.elementType == KtTokens.LBRACE || it is PsiWhiteSpace && it.getText()!!.count { it == '\n' } > 1
|
||||||
it is PsiWhiteSpace && it.getText()!!.count { it == '\n' } > 1
|
|
||||||
}
|
}
|
||||||
?.siblings(forward = true, withItself = false)
|
?.siblings(forward = true, withItself = false)
|
||||||
?.dropWhile { it is PsiWhiteSpace } // and take first non-whitespace element after it
|
?.dropWhile { it is PsiWhiteSpace } // and take first non-whitespace element after it
|
||||||
@@ -53,14 +52,13 @@ class KotlinStatementGroupSelectioner : ExtendWordSelectionHandlerBase() {
|
|||||||
val endElement = e.siblings(forward = true, withItself = false)
|
val endElement = e.siblings(forward = true, withItself = false)
|
||||||
.firstOrNull {
|
.firstOrNull {
|
||||||
// find next '}' or blank line
|
// find next '}' or blank line
|
||||||
it is LeafPsiElement && it.elementType == KtTokens.RBRACE ||
|
it is LeafPsiElement && it.elementType == KtTokens.RBRACE || it is PsiWhiteSpace && it.getText()!!.count { it == '\n' } > 1
|
||||||
it is PsiWhiteSpace && it.getText()!!.count { it == '\n' } > 1
|
|
||||||
}
|
}
|
||||||
?.siblings(forward = false, withItself = false)
|
?.siblings(forward = false, withItself = false)
|
||||||
?.dropWhile { it is PsiWhiteSpace } // and take first non-whitespace element before it
|
?.dropWhile { it is PsiWhiteSpace } // and take first non-whitespace element before it
|
||||||
?.firstOrNull() ?: parent.lastChild!!
|
?.firstOrNull() ?: parent.lastChild!!
|
||||||
|
|
||||||
return ExtendWordSelectionHandlerBase.expandToWholeLine(
|
return expandToWholeLine(
|
||||||
editorText,
|
editorText,
|
||||||
TextRange(
|
TextRange(
|
||||||
startElement.textRange!!.startOffset,
|
startElement.textRange!!.startOffset,
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo(f: (Int) -> Int) {}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
foo { <caret>it -> it + 1 }
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo(f: (Int) -> Int) {}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
foo { <caret><selection>it</selection> -> it + 1 }
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo(f: (Int) -> Int) {}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
foo { <caret><selection>it -> it + 1</selection> }
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo(f: (Int) -> Int) {}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
foo <selection>{ <caret>it -> it + 1 }</selection>
|
||||||
|
}
|
||||||
@@ -49,6 +49,8 @@ public class WordSelectionTest extends KotlinLightCodeInsightFixtureTestCase {
|
|||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testValueParametersInLambda() { doTest(); }
|
||||||
|
|
||||||
public void testDocComment() { doTest(); }
|
public void testDocComment() { doTest(); }
|
||||||
|
|
||||||
public void testDocCommentOneLine() { doTest(); }
|
public void testDocCommentOneLine() { doTest(); }
|
||||||
|
|||||||
Reference in New Issue
Block a user