Improved word selection for parameters and arguments.
#KT-1657 fixed
This commit is contained in:
@@ -135,6 +135,7 @@
|
||||
|
||||
<extendWordSelectionHandler implementation="org.jetbrains.jet.plugin.editor.wordSelection.JetStatementGroupSelectioner"/>
|
||||
<extendWordSelectionHandler implementation="org.jetbrains.jet.plugin.editor.wordSelection.JetCodeBlockSelectioner"/>
|
||||
<extendWordSelectionHandler implementation="org.jetbrains.jet.plugin.editor.wordSelection.JetListSelectioner"/>
|
||||
|
||||
<documentationProvider implementation="org.jetbrains.jet.plugin.JetQuickDocumentationProvider"/>
|
||||
<configurationType implementation="org.jetbrains.jet.plugin.run.JetRunConfigurationType"/>
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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.jet.plugin.editor.wordSelection;
|
||||
|
||||
import com.intellij.codeInsight.editorActions.wordSelection.BasicSelectioner;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.jet.lang.psi.JetParameterList;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeArgumentList;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeParameterList;
|
||||
import org.jetbrains.jet.lang.psi.JetValueArgumentList;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Evgeny Gerashchenko
|
||||
* @since 4/23/12
|
||||
*/
|
||||
public class JetListSelectioner extends BasicSelectioner {
|
||||
@Override
|
||||
public boolean canSelect(PsiElement e) {
|
||||
return e instanceof JetParameterList || e instanceof JetValueArgumentList ||
|
||||
e instanceof JetTypeParameterList || e instanceof JetTypeArgumentList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
|
||||
ASTNode node = e.getNode();
|
||||
ASTNode startNode = node.findChildByType(TokenSet.create(JetTokens.LPAR, JetTokens.LT));
|
||||
ASTNode endNode = node.findChildByType(TokenSet.create(JetTokens.RPAR, JetTokens.GT));
|
||||
if (startNode != null && endNode != null) {
|
||||
return Arrays.asList(new TextRange(startNode.getStartOffset() + 1, endNode.getStartOffset()));
|
||||
} else {
|
||||
return Arrays.asList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun <A, B> foo() {
|
||||
foo<<selection>I<caret>nt, B</selection>>()
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun <A, B> foo() {
|
||||
foo<<selection>I<caret>nt</selection>, B>()
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fun <<selection>A, <caret>B</selection>> foo() {
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fun <A, <selection><caret>B</selection>> foo() {
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo() {
|
||||
foo(<selection><caret>1, 2</selection>)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo() {
|
||||
foo(<selection><caret>1</selection>, 2)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fun foo(<selection>a : Array<String>, <caret>b : Int</selection>) {
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fun foo(a : Array<String>, <selection><caret>b : Int</selection>) {
|
||||
}
|
||||
@@ -35,6 +35,22 @@ public class WordSelectionTest extends LightCodeInsightFixtureTestCase {
|
||||
doTest(6);
|
||||
}
|
||||
|
||||
public void testTypeArguments() {
|
||||
doTest(1);
|
||||
}
|
||||
|
||||
public void testValueArguments() {
|
||||
doTest(1);
|
||||
}
|
||||
|
||||
public void testTypeParameters() {
|
||||
doTest(1);
|
||||
}
|
||||
|
||||
public void testValueParameters() {
|
||||
doTest(1);
|
||||
}
|
||||
|
||||
private void doTest(int howMany) {
|
||||
String testName = getTestName(false);
|
||||
String[] afterFiles = new String[howMany];
|
||||
|
||||
Reference in New Issue
Block a user