Extend selection: select just KDoc if cursor is just before the KDoc (KT-16476)

#KT-16476 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-05-23 10:03:49 +09:00
committed by Nikolay Krasko
parent 8afa938723
commit c442d69db6
5 changed files with 44 additions and 0 deletions
@@ -55,6 +55,10 @@ class KotlinDeclarationSelectioner : ExtendWordSelectionHandlerBase() {
.siblings(forward = false, withItself = true)
.first { it !is PsiComment && it !is PsiWhiteSpace }
if (firstComment != null && cursorOffset <= firstComment.startOffset) {
result.addRange(editorText, TextRange(firstComment.startOffset, firstComment.endOffset))
}
if (firstComment != null || lastComment != null) {
val startOffset = minOf(
firstComment?.startOffset ?: Int.MAX_VALUE,
@@ -0,0 +1,13 @@
class C {
fun foo() {
}
<caret> /**
* comment
*/
fun bar() {
}
fun baz() {
}
}
@@ -0,0 +1,13 @@
class C {
fun foo() {
}
<selection><caret> /**
* comment
*/
</selection> fun bar() {
}
fun baz() {
}
}
@@ -0,0 +1,13 @@
class C {
fun foo() {
}
<selection><caret> /**
* comment
*/
fun bar() {
}
</selection>
fun baz() {
}
}
@@ -123,6 +123,7 @@ public class WordSelectionTest extends KotlinLightCodeInsightFixtureTestCase {
public void testDeclarationWithComment2() { doTest(); }
public void testDeclarationWithComment3() { doTest(); }
public void testDeclarationWithComment4() { doTest(); }
public void testDeclarationWithDocComment() { doTest(); }
public void testLeftBrace() { doTest(); }
public void testRightBrace() { doTest(); }