KT-5292 Expand selection should have kdoc + method as a stop point
KT-3947 Extend selection works badly with comment #KT-5292 Fixed #KT-3947 Fixed
This commit is contained in:
@@ -318,6 +318,8 @@
|
||||
|
||||
<extendWordSelectionHandler implementation="org.jetbrains.jet.plugin.editor.wordSelection.KotlinStatementGroupSelectioner"/>
|
||||
<extendWordSelectionHandler implementation="org.jetbrains.jet.plugin.editor.wordSelection.KotlinCodeBlockSelectioner"/>
|
||||
<extendWordSelectionHandler implementation="org.jetbrains.jet.plugin.editor.wordSelection.KotlinDocCommentSelectioner"/>
|
||||
<extendWordSelectionHandler implementation="org.jetbrains.jet.plugin.editor.wordSelection.KotlinDeclarationSelectioner"/>
|
||||
<extendWordSelectionHandler implementation="org.jetbrains.jet.plugin.editor.wordSelection.KotlinListSelectioner"/>
|
||||
|
||||
<typedHandler implementation="org.jetbrains.jet.plugin.editor.KotlinTypedHandler"/>
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.psi.PsiElement
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.siblings
|
||||
import com.intellij.psi.PsiComment
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
|
||||
public class KotlinDeclarationSelectioner : BasicSelectioner() {
|
||||
override fun canSelect(e: PsiElement)
|
||||
= e is JetDeclaration
|
||||
|
||||
override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List<TextRange>? {
|
||||
val result = ArrayList<TextRange>()
|
||||
|
||||
val firstChild = e.getFirstChild()
|
||||
val firstNonComment = firstChild
|
||||
.siblings(forward = true, withItself = true)
|
||||
.first { it !is PsiComment && it !is PsiWhiteSpace }
|
||||
|
||||
val lastChild = e.getLastChild()
|
||||
val lastNonComment = lastChild
|
||||
.siblings(forward = false, withItself = true)
|
||||
.first { it !is PsiComment && it !is PsiWhiteSpace }
|
||||
|
||||
if (firstNonComment != firstChild || lastNonComment != lastChild) {
|
||||
val start = firstNonComment.getTextRange().getStartOffset()
|
||||
val end = lastNonComment.getTextRange().getEndOffset()
|
||||
result.addAll(ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, TextRange(start, end)))
|
||||
}
|
||||
|
||||
result.addAll(ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, e.getTextRange()))
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.PsiWhiteSpace
|
||||
import org.jetbrains.jet.lexer.JetTokens
|
||||
|
||||
import java.util.ArrayList
|
||||
import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase
|
||||
import org.jetbrains.jet.kdoc.psi.api.KDoc
|
||||
|
||||
public class KotlinDocCommentSelectioner : BasicSelectioner() {
|
||||
override fun canSelect(e: PsiElement)
|
||||
= e is KDoc
|
||||
|
||||
override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List<TextRange>? {
|
||||
return ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, e.getTextRange())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package p
|
||||
|
||||
/**
|
||||
* Doc comment <caret>here
|
||||
*/
|
||||
fun foo() {
|
||||
}
|
||||
|
||||
fun bar(){}
|
||||
@@ -0,0 +1,9 @@
|
||||
package p
|
||||
|
||||
/**
|
||||
* Doc comment <selection><caret>here</selection>
|
||||
*/
|
||||
fun foo() {
|
||||
}
|
||||
|
||||
fun bar(){}
|
||||
@@ -0,0 +1,9 @@
|
||||
package p
|
||||
|
||||
/**
|
||||
*<selection> Doc comment <caret>here</selection>
|
||||
*/
|
||||
fun foo() {
|
||||
}
|
||||
|
||||
fun bar(){}
|
||||
@@ -0,0 +1,9 @@
|
||||
package p
|
||||
|
||||
<selection>/**
|
||||
* Doc comment <caret>here
|
||||
*/
|
||||
</selection>fun foo() {
|
||||
}
|
||||
|
||||
fun bar(){}
|
||||
@@ -0,0 +1,9 @@
|
||||
package p
|
||||
|
||||
<selection>/**
|
||||
* Doc comment <caret>here
|
||||
*/
|
||||
fun foo() {
|
||||
}
|
||||
</selection>
|
||||
fun bar(){}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun a() : <caret>Int {} // fun a
|
||||
|
||||
fun b() : Short {
|
||||
f()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun a() : <selection><caret>Int</selection> {} // fun a
|
||||
|
||||
fun b() : Short {
|
||||
f()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<selection>fun a() : <caret>Int {}</selection> // fun a
|
||||
|
||||
fun b() : Short {
|
||||
f()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<selection>fun a() : <caret>Int {} // fun a</selection>
|
||||
|
||||
fun b() : Short {
|
||||
f()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<selection>fun a() : <caret>Int {} // fun a
|
||||
</selection>
|
||||
fun b() : Short {
|
||||
f()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun a() : Int {}
|
||||
|
||||
// TODO: Refactor
|
||||
fun b() : <caret>Short {
|
||||
f()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun a() : Int {}
|
||||
|
||||
// TODO: Refactor
|
||||
fun b() : <selection><caret>Short</selection> {
|
||||
f()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun a() : Int {}
|
||||
|
||||
// TODO: Refactor
|
||||
<selection>fun b() : <caret>Short {
|
||||
f()
|
||||
}
|
||||
</selection>
|
||||
@@ -0,0 +1,7 @@
|
||||
fun a() : Int {}
|
||||
|
||||
<selection>// TODO: Refactor
|
||||
fun b() : <caret>Short {
|
||||
f()
|
||||
}
|
||||
</selection>
|
||||
@@ -0,0 +1,8 @@
|
||||
package p
|
||||
|
||||
class C{
|
||||
// This is a <caret>val
|
||||
val v = 1
|
||||
|
||||
fun foo(){}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package p
|
||||
|
||||
class C{
|
||||
// This is a <selection><caret>val</selection>
|
||||
val v = 1
|
||||
|
||||
fun foo(){}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package p
|
||||
|
||||
class C{
|
||||
// <selection>This is a <caret>val</selection>
|
||||
val v = 1
|
||||
|
||||
fun foo(){}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package p
|
||||
|
||||
class C{
|
||||
<selection>// This is a <caret>val</selection>
|
||||
val v = 1
|
||||
|
||||
fun foo(){}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package p
|
||||
|
||||
class C{
|
||||
<selection> // This is a <caret>val
|
||||
</selection> val v = 1
|
||||
|
||||
fun foo(){}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package p
|
||||
|
||||
class C{
|
||||
<selection> // This is a <caret>val
|
||||
val v = 1
|
||||
</selection>
|
||||
fun foo(){}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package p
|
||||
|
||||
/* This is a <caret>comment */
|
||||
fun foo() {
|
||||
}
|
||||
|
||||
fun bar(){}
|
||||
@@ -0,0 +1,7 @@
|
||||
package p
|
||||
|
||||
/* This is a <selection><caret>comment</selection> */
|
||||
fun foo() {
|
||||
}
|
||||
|
||||
fun bar(){}
|
||||
@@ -0,0 +1,7 @@
|
||||
package p
|
||||
|
||||
<selection>/* This is a <caret>comment */</selection>
|
||||
fun foo() {
|
||||
}
|
||||
|
||||
fun bar(){}
|
||||
@@ -0,0 +1,7 @@
|
||||
package p
|
||||
|
||||
<selection>/* This is a <caret>comment */
|
||||
</selection>fun foo() {
|
||||
}
|
||||
|
||||
fun bar(){}
|
||||
@@ -0,0 +1,7 @@
|
||||
package p
|
||||
|
||||
<selection>/* This is a <caret>comment */
|
||||
fun foo() {
|
||||
}
|
||||
</selection>
|
||||
fun bar(){}
|
||||
@@ -10,7 +10,7 @@ fun main(args : Array<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
<selection>fun foo() : Unit {
|
||||
fun foo() : Unit <selection>{
|
||||
println() {
|
||||
println()
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<selection>fun main(args : Array<String>) {
|
||||
fun main(args : Array<String>) {
|
||||
for (i in 1..100) {
|
||||
when {
|
||||
i%3 == 0 -> {print("Fizz"); continue;}
|
||||
@@ -10,7 +10,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
fun foo() : Unit {
|
||||
<selection>fun foo() : Unit {
|
||||
println() {
|
||||
println()
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<selection>fun main(args : Array<String>) {
|
||||
for (i in 1..100) {
|
||||
when {
|
||||
i%3 == 0 -> {print("Fizz"); continue;}
|
||||
i%5 == 0 -> {print("Buzz"); continue;}
|
||||
|
||||
(i%3 != 0 && i%5 != 0) -> {print(i); continue;}
|
||||
else -> println()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun foo() : Unit {
|
||||
println() {
|
||||
println()
|
||||
|
||||
|
||||
pr<caret>intln()
|
||||
println()
|
||||
}
|
||||
|
||||
println(array(1, 2, 3))
|
||||
println()
|
||||
}</selection>
|
||||
@@ -17,8 +17,8 @@ fun foo() : Unit {
|
||||
|
||||
pr<caret>intln()
|
||||
println()
|
||||
}
|
||||
</selection>
|
||||
}</selection>
|
||||
|
||||
println(array(1, 2, 3))
|
||||
println()
|
||||
}
|
||||
@@ -11,7 +11,7 @@ fun main(args : Array<String>) {
|
||||
}
|
||||
|
||||
fun foo() : Unit {
|
||||
<selection> println() {
|
||||
println() <selection>{
|
||||
println()
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ fun foo() : Unit {
|
||||
pr<caret>intln()
|
||||
println()
|
||||
}
|
||||
|
||||
</selection>
|
||||
println(array(1, 2, 3))
|
||||
println()
|
||||
</selection>}
|
||||
}
|
||||
@@ -10,8 +10,8 @@ fun main(args : Array<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
fun foo() : Unit <selection>{
|
||||
println() {
|
||||
fun foo() : Unit {
|
||||
<selection> println() {
|
||||
println()
|
||||
|
||||
|
||||
@@ -21,4 +21,4 @@ fun foo() : Unit <selection>{
|
||||
|
||||
println(array(1, 2, 3))
|
||||
println()
|
||||
}</selection>
|
||||
</selection>}
|
||||
@@ -23,29 +23,27 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.io.File;
|
||||
|
||||
public class WordSelectionTest extends JetLightCodeInsightFixtureTestCase {
|
||||
public void testStatements() {
|
||||
doTest();
|
||||
}
|
||||
public void testStatements() { doTest(); }
|
||||
|
||||
public void testWhenEntries() {
|
||||
doTest();
|
||||
}
|
||||
public void testWhenEntries() { doTest(); }
|
||||
|
||||
public void testTypeArguments() {
|
||||
doTest();
|
||||
}
|
||||
public void testTypeArguments() { doTest(); }
|
||||
|
||||
public void testValueArguments() {
|
||||
doTest();
|
||||
}
|
||||
public void testValueArguments() { doTest(); }
|
||||
|
||||
public void testTypeParameters() {
|
||||
doTest();
|
||||
}
|
||||
public void testTypeParameters() { doTest(); }
|
||||
|
||||
public void testValueParameters() {
|
||||
doTest();
|
||||
}
|
||||
public void testValueParameters() { doTest(); }
|
||||
|
||||
public void testDocComment() { doTest(); }
|
||||
|
||||
public void testFunctionWithLineCommentBefore() { doTest(); }
|
||||
|
||||
public void testFunctionWithLineCommentAfter() { doTest(); }
|
||||
|
||||
public void testLineComment() { doTest(); }
|
||||
|
||||
public void testSimpleComment() { doTest(); }
|
||||
|
||||
private void doTest() {
|
||||
String dirName = getTestName(false);
|
||||
|
||||
Reference in New Issue
Block a user