Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
c6a155c3
Commit
c6a155c3
authored
6 years ago
by
Dmitry Batrak
Browse files
Options
Download
Email Patches
Plain Diff
IDEA-200275 Multiline TODO: support line Split in block comments
parent
56300a71
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
platform/lang-impl/src/com/intellij/codeInsight/editorActions/enter/EnterInBlockCommentHandler.java
+22
-2
...sight/editorActions/enter/EnterInBlockCommentHandler.java
platform/lang-impl/src/com/intellij/codeInsight/editorActions/enter/EnterInCommentUtil.java
+19
-0
...j/codeInsight/editorActions/enter/EnterInCommentUtil.java
platform/lang-impl/src/com/intellij/codeInsight/editorActions/enter/EnterInLineCommentHandler.java
+2
-8
...nsight/editorActions/enter/EnterInLineCommentHandler.java
with
43 additions
and
10 deletions
+43
-10
platform/lang-impl/src/com/intellij/codeInsight/editorActions/enter/EnterInBlockCommentHandler.java
+
22
-
2
View file @
c6a155c3
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
package
com.intellij.codeInsight.editorActions.enter
;
package
com.intellij.codeInsight.editorActions.enter
;
import
com.intellij.codeInsight.editorActions.EnterHandler
;
import
com.intellij.codeInsight.editorActions.EnterHandler
;
import
com.intellij.ide.todo.TodoConfiguration
;
import
com.intellij.lang.CodeDocumentationAwareCommenter
;
import
com.intellij.lang.CodeDocumentationAwareCommenter
;
import
com.intellij.openapi.actionSystem.DataContext
;
import
com.intellij.openapi.actionSystem.DataContext
;
import
com.intellij.openapi.editor.Document
;
import
com.intellij.openapi.editor.Document
;
...
@@ -17,6 +18,7 @@ import com.intellij.psi.PsiComment;
...
@@ -17,6 +18,7 @@ import com.intellij.psi.PsiComment;
import
com.intellij.psi.PsiDocumentManager
;
import
com.intellij.psi.PsiDocumentManager
;
import
com.intellij.psi.PsiElement
;
import
com.intellij.psi.PsiElement
;
import
com.intellij.psi.PsiFile
;
import
com.intellij.psi.PsiFile
;
import
com.intellij.util.DocumentUtil
;
import
com.intellij.util.ObjectUtils
;
import
com.intellij.util.ObjectUtils
;
import
com.intellij.util.text.CharArrayUtil
;
import
com.intellij.util.text.CharArrayUtil
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.NotNull
;
...
@@ -63,6 +65,22 @@ public class EnterInBlockCommentHandler extends EnterHandlerDelegateAdapter {
...
@@ -63,6 +65,22 @@ public class EnterInBlockCommentHandler extends EnterHandlerDelegateAdapter {
return
Result
.
Default
;
return
Result
.
Default
;
}
}
int
additionalIndent
=
0
;
if
(
TodoConfiguration
.
getInstance
().
isMultiLine
())
{
int
lineStartOffset
=
DocumentUtil
.
getLineStartOffset
(
caretOffset
,
document
);
int
todoOffset
=
EnterInCommentUtil
.
getTodoTextOffset
(
text
,
lineStartOffset
,
caretOffset
);
if
(
todoOffset
>=
0
)
{
int
lineEndOffset
=
DocumentUtil
.
getLineEndOffset
(
caretOffset
,
document
);
if
(
todoOffset
==
EnterInCommentUtil
.
getTodoTextOffset
(
text
,
lineStartOffset
,
lineEndOffset
))
{
int
nonWsLineStart
=
CharArrayUtil
.
shiftForward
(
text
,
lineStartOffset
,
WHITESPACE
);
if
(
todoOffset
>=
nonWsLineStart
)
{
additionalIndent
=
todoOffset
-
nonWsLineStart
+
1
;
document
.
insertString
(
caretOffset
,
StringUtil
.
repeat
(
" "
,
additionalIndent
));
}
}
}
}
String
linePrefix
=
commenter
.
getDocumentationCommentLinePrefix
();
String
linePrefix
=
commenter
.
getDocumentationCommentLinePrefix
();
if
(
linePrefix
==
null
)
return
Result
.
Continue
;
if
(
linePrefix
==
null
)
return
Result
.
Continue
;
...
@@ -71,8 +89,10 @@ public class EnterInBlockCommentHandler extends EnterHandlerDelegateAdapter {
...
@@ -71,8 +89,10 @@ public class EnterInBlockCommentHandler extends EnterHandlerDelegateAdapter {
if
(
StringUtil
.
startsWith
(
text
,
CharArrayUtil
.
shiftForward
(
text
,
refOffset
,
WHITESPACE
),
linePrefix
))
{
if
(
StringUtil
.
startsWith
(
text
,
CharArrayUtil
.
shiftForward
(
text
,
refOffset
,
WHITESPACE
),
linePrefix
))
{
int
endOffset
=
CharArrayUtil
.
shiftForward
(
text
,
caretOffset
,
WHITESPACE
);
int
endOffset
=
CharArrayUtil
.
shiftForward
(
text
,
caretOffset
,
WHITESPACE
);
if
(
endOffset
<
text
.
length
()
&&
text
.
charAt
(
endOffset
)
!=
'\n'
)
endOffset
=
caretOffset
;
if
(
endOffset
<
text
.
length
()
&&
text
.
charAt
(
endOffset
)
!=
'\n'
)
endOffset
=
caretOffset
;
document
.
replaceString
(
caretOffset
,
endOffset
,
linePrefix
+
" "
);
int
valueLength
=
linePrefix
.
length
()
+
1
;
caretAdvance
.
set
(
linePrefix
.
length
()
+
1
);
int
endOffsetToReplace
=
endOffset
>
caretOffset
?
endOffset
:
caretOffset
+
Math
.
min
(
additionalIndent
,
valueLength
);
document
.
replaceString
(
caretOffset
,
endOffsetToReplace
,
linePrefix
+
" "
);
caretAdvance
.
set
(
Math
.
max
(
valueLength
,
additionalIndent
));
return
Result
.
DefaultForceIndent
;
return
Result
.
DefaultForceIndent
;
}
}
return
Result
.
Continue
;
return
Result
.
Continue
;
...
...
This diff is collapsed.
Click to expand it.
platform/lang-impl/src/com/intellij/codeInsight/editorActions/enter/EnterInCommentUtil.java
+
19
-
0
View file @
c6a155c3
...
@@ -2,14 +2,18 @@
...
@@ -2,14 +2,18 @@
package
com.intellij.codeInsight.editorActions.enter
;
package
com.intellij.codeInsight.editorActions.enter
;
import
com.intellij.codeInsight.editorActions.EnterHandler
;
import
com.intellij.codeInsight.editorActions.EnterHandler
;
import
com.intellij.ide.todo.TodoConfiguration
;
import
com.intellij.lang.CodeDocumentationAwareCommenter
;
import
com.intellij.lang.CodeDocumentationAwareCommenter
;
import
com.intellij.lang.Commenter
;
import
com.intellij.lang.Commenter
;
import
com.intellij.lang.Language
;
import
com.intellij.lang.Language
;
import
com.intellij.lang.LanguageCommenters
;
import
com.intellij.lang.LanguageCommenters
;
import
com.intellij.openapi.actionSystem.DataContext
;
import
com.intellij.openapi.actionSystem.DataContext
;
import
com.intellij.psi.search.TodoPattern
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.annotations.Nullable
;
import
java.util.regex.Matcher
;
public
class
EnterInCommentUtil
{
public
class
EnterInCommentUtil
{
@Nullable
@Nullable
public
static
CodeDocumentationAwareCommenter
getDocumentationAwareCommenter
(
@NotNull
DataContext
dataContext
)
{
public
static
CodeDocumentationAwareCommenter
getDocumentationAwareCommenter
(
@NotNull
DataContext
dataContext
)
{
...
@@ -20,4 +24,19 @@ public class EnterInCommentUtil {
...
@@ -20,4 +24,19 @@ public class EnterInCommentUtil {
return
languageCommenter
instanceof
CodeDocumentationAwareCommenter
return
languageCommenter
instanceof
CodeDocumentationAwareCommenter
?
(
CodeDocumentationAwareCommenter
)
languageCommenter
:
null
;
?
(
CodeDocumentationAwareCommenter
)
languageCommenter
:
null
;
}
}
public
static
boolean
isTodoText
(
@NotNull
CharSequence
text
,
int
startOffset
,
int
endOffset
)
{
return
getTodoTextOffset
(
text
,
startOffset
,
endOffset
)
>=
0
;
}
public
static
int
getTodoTextOffset
(
@NotNull
CharSequence
text
,
int
startOffset
,
int
endOffset
)
{
CharSequence
input
=
text
.
subSequence
(
startOffset
,
endOffset
);
for
(
TodoPattern
pattern
:
TodoConfiguration
.
getInstance
().
getTodoPatterns
())
{
Matcher
matcher
=
pattern
.
getPattern
().
matcher
(
input
);
if
(
matcher
.
find
())
{
return
startOffset
+
matcher
.
start
();
}
}
return
-
1
;
}
}
}
This diff is collapsed.
Click to expand it.
platform/lang-impl/src/com/intellij/codeInsight/editorActions/enter/EnterInLineCommentHandler.java
+
2
-
8
View file @
c6a155c3
...
@@ -29,7 +29,6 @@ import com.intellij.openapi.util.Ref;
...
@@ -29,7 +29,6 @@ import com.intellij.openapi.util.Ref;
import
com.intellij.openapi.util.text.StringUtil
;
import
com.intellij.openapi.util.text.StringUtil
;
import
com.intellij.psi.PsiFile
;
import
com.intellij.psi.PsiFile
;
import
com.intellij.util.DocumentUtil
;
import
com.intellij.util.DocumentUtil
;
import
com.intellij.util.containers.ContainerUtil
;
import
com.intellij.util.text.CharArrayUtil
;
import
com.intellij.util.text.CharArrayUtil
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.NotNull
;
...
@@ -76,8 +75,8 @@ public class EnterInLineCommentHandler extends EnterHandlerDelegateAdapter {
...
@@ -76,8 +75,8 @@ public class EnterInLineCommentHandler extends EnterHandlerDelegateAdapter {
int
indentEnd
=
CharArrayUtil
.
shiftForward
(
text
,
indentStart
,
WHITESPACE
);
int
indentEnd
=
CharArrayUtil
.
shiftForward
(
text
,
indentStart
,
WHITESPACE
);
CharSequence
currentLineSpacing
=
text
.
subSequence
(
indentStart
,
indentEnd
);
CharSequence
currentLineSpacing
=
text
.
subSequence
(
indentStart
,
indentEnd
);
if
(
TodoConfiguration
.
getInstance
().
isMultiLine
()
&&
if
(
TodoConfiguration
.
getInstance
().
isMultiLine
()
&&
isTodoText
(
text
,
lineCommentStartOffset
,
caretOffset
)
&&
EnterInCommentUtil
.
isTodoText
(
text
,
lineCommentStartOffset
,
caretOffset
)
&&
isTodoText
(
text
,
lineCommentStartOffset
,
DocumentUtil
.
getLineEndOffset
(
lineCommentStartOffset
,
document
)))
{
EnterInCommentUtil
.
isTodoText
(
text
,
lineCommentStartOffset
,
DocumentUtil
.
getLineEndOffset
(
lineCommentStartOffset
,
document
)))
{
spacing
=
currentLineSpacing
+
" "
;
spacing
=
currentLineSpacing
+
" "
;
}
}
else
if
(
currentLineSpacing
.
length
()
>
0
)
{
else
if
(
currentLineSpacing
.
length
()
>
0
)
{
...
@@ -106,9 +105,4 @@ public class EnterInLineCommentHandler extends EnterHandlerDelegateAdapter {
...
@@ -106,9 +105,4 @@ public class EnterInLineCommentHandler extends EnterHandlerDelegateAdapter {
return
iterator
.
getTokenType
()
==
commenter
.
getLineCommentTokenType
()
&&
return
iterator
.
getTokenType
()
==
commenter
.
getLineCommentTokenType
()
&&
(
iterator
.
getStart
()
+
(
prefix
==
null
?
0
:
prefix
.
length
()))
<=
offset
?
iterator
.
getStart
()
:
-
1
;
(
iterator
.
getStart
()
+
(
prefix
==
null
?
0
:
prefix
.
length
()))
<=
offset
?
iterator
.
getStart
()
:
-
1
;
}
}
private
static
boolean
isTodoText
(
@NotNull
CharSequence
text
,
int
startOffset
,
int
endOffset
)
{
CharSequence
input
=
text
.
subSequence
(
startOffset
,
endOffset
);
return
ContainerUtil
.
exists
(
TodoConfiguration
.
getInstance
().
getTodoPatterns
(),
pattern
->
pattern
.
getPattern
().
matcher
(
input
).
find
());
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help