From c442d69db6996d19973f69d0915feb3eb85ca7a6 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Thu, 23 May 2019 10:03:49 +0900 Subject: [PATCH] Extend selection: select just KDoc if cursor is just before the KDoc (KT-16476) #KT-16476 Fixed --- .../wordSelection/KotlinDeclarationSelectioner.kt | 4 ++++ .../wordSelection/DeclarationWithDocComment/0.kt | 13 +++++++++++++ .../wordSelection/DeclarationWithDocComment/1.kt | 13 +++++++++++++ .../wordSelection/DeclarationWithDocComment/2.kt | 13 +++++++++++++ .../jetbrains/kotlin/idea/WordSelectionTest.java | 1 + 5 files changed, 44 insertions(+) create mode 100644 idea/testData/wordSelection/DeclarationWithDocComment/0.kt create mode 100644 idea/testData/wordSelection/DeclarationWithDocComment/1.kt create mode 100644 idea/testData/wordSelection/DeclarationWithDocComment/2.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinDeclarationSelectioner.kt b/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinDeclarationSelectioner.kt index 158ef158abd..c5105822604 100644 --- a/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinDeclarationSelectioner.kt +++ b/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinDeclarationSelectioner.kt @@ -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, diff --git a/idea/testData/wordSelection/DeclarationWithDocComment/0.kt b/idea/testData/wordSelection/DeclarationWithDocComment/0.kt new file mode 100644 index 00000000000..7d148d60e16 --- /dev/null +++ b/idea/testData/wordSelection/DeclarationWithDocComment/0.kt @@ -0,0 +1,13 @@ +class C { + fun foo() { + } + + /** + * comment + */ + fun bar() { + } + + fun baz() { + } +} \ No newline at end of file diff --git a/idea/testData/wordSelection/DeclarationWithDocComment/1.kt b/idea/testData/wordSelection/DeclarationWithDocComment/1.kt new file mode 100644 index 00000000000..94a83bffc23 --- /dev/null +++ b/idea/testData/wordSelection/DeclarationWithDocComment/1.kt @@ -0,0 +1,13 @@ +class C { + fun foo() { + } + + /** + * comment + */ + fun bar() { + } + + fun baz() { + } +} \ No newline at end of file diff --git a/idea/testData/wordSelection/DeclarationWithDocComment/2.kt b/idea/testData/wordSelection/DeclarationWithDocComment/2.kt new file mode 100644 index 00000000000..e5aadf7b678 --- /dev/null +++ b/idea/testData/wordSelection/DeclarationWithDocComment/2.kt @@ -0,0 +1,13 @@ +class C { + fun foo() { + } + + /** + * comment + */ + fun bar() { + } + + fun baz() { + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java b/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java index 899244ecb32..ae3939e7844 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java @@ -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(); }