Select lambda after other args when it's outside argument list (KT-21214)
#KT-21214 Fixed
This commit is contained in:
committed by
Nikolay Krasko
parent
976a158ce1
commit
809cc220ed
@@ -552,6 +552,7 @@
|
|||||||
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinStatementGroupSelectioner"/>
|
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinStatementGroupSelectioner"/>
|
||||||
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinCodeBlockSelectioner"/>
|
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinCodeBlockSelectioner"/>
|
||||||
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinDocCommentSelectioner"/>
|
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinDocCommentSelectioner"/>
|
||||||
|
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinCallExpressionWithLambdaSelectioner"/>
|
||||||
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinDeclarationSelectioner"/>
|
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinDeclarationSelectioner"/>
|
||||||
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinListSelectioner"/>
|
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinListSelectioner"/>
|
||||||
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinStringLiteralSelectioner"/>
|
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinStringLiteralSelectioner"/>
|
||||||
|
|||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.editor.wordSelection
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import com.intellij.openapi.util.TextRange
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||||
|
|
||||||
|
class KotlinCallExpressionWithLambdaSelectioner : ExtendWordSelectionHandlerBase() {
|
||||||
|
|
||||||
|
override fun canSelect(e: PsiElement): Boolean
|
||||||
|
= e is KtCallExpression && e.hasLambda()
|
||||||
|
|
||||||
|
override fun select(e: PsiElement?, editorText: CharSequence?, cursorOffset: Int, editor: Editor?): List<TextRange>? {
|
||||||
|
if (e !is KtCallExpression) return null
|
||||||
|
|
||||||
|
val endOffset = e.valueArgumentList?.endOffset ?: return null
|
||||||
|
return listOf(TextRange(e.startOffset, endOffset))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun KtCallExpression.hasLambda(): Boolean
|
||||||
|
= lambdaArguments.isNotEmpty()
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
fo<caret>o(1, 2) {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
<selection>fo<caret>o</selection>(1, 2) {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
<selection>fo<caret>o(1, 2)</selection> {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
<selection> fo<caret>o(1, 2) {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
</selection>}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
fo<caret>o {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
<selection>fo<caret>o</selection> {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
<selection> fo<caret>o {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
</selection>}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
fo<caret>o({
|
||||||
|
1
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
<selection>fo<caret>o</selection>({
|
||||||
|
1
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
<selection> fo<caret>o({
|
||||||
|
1
|
||||||
|
})
|
||||||
|
</selection>}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
fo<caret>o() {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
<selection>fo<caret>o</selection>() {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
<selection>fo<caret>o()</selection> {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
<selection> fo<caret>o() {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
</selection>}
|
||||||
@@ -108,6 +108,19 @@ public class WordSelectionTest extends KotlinLightCodeInsightFixtureTestCase {
|
|||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testLambdaArgument1() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
public void testLambdaArgument2() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
public void testLambdaArgument3() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
public void testLambdaArgument4() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
public void testArrayBrackets() {
|
public void testArrayBrackets() {
|
||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user