mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
CommentFoldingUtil: fixed folding for case when line with javadoc contains code or another comment (IDEA-218068)
GitOrigin-RevId: 254059119248f79716843f217dcdbaabdfef6f47
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8254d5524c
commit
bed88876d9
+14
-6
@@ -248,7 +248,7 @@ public final class CommentFoldingUtil {
|
||||
final int nFirstCommentLine = document.getLineNumber(commentRange.getStartOffset());
|
||||
|
||||
TextRange lineRange = getLineRange(document, nFirstCommentLine);
|
||||
String line = getCommentLine(document, lineRange, commentPrefix, commentSuffix);
|
||||
String line = getCommentLine(document, lineRange, commentRange, commentPrefix, commentSuffix);
|
||||
|
||||
if (line.chars().anyMatch(c -> !StringUtil.isWhiteSpace((char)c))) return line;
|
||||
|
||||
@@ -257,7 +257,7 @@ public final class CommentFoldingUtil {
|
||||
|
||||
lineRange = getLineRange(document, nSecondCommentLine);
|
||||
if (lineRange.getEndOffset() > commentRange.getEndOffset()) return "";
|
||||
line = getCommentLine(document, lineRange, linePrefix, commentSuffix);
|
||||
line = getCommentLine(document, lineRange, commentRange, linePrefix, commentSuffix);
|
||||
|
||||
if (line.chars().anyMatch(c -> !StringUtil.isWhiteSpace((char)c))) return line;
|
||||
|
||||
@@ -275,12 +275,20 @@ public final class CommentFoldingUtil {
|
||||
@NotNull
|
||||
private static String getCommentLine(@NotNull Document document,
|
||||
@NotNull TextRange lineRange,
|
||||
@NotNull TextRange commentRange,
|
||||
@NotNull String prefix,
|
||||
@NotNull String suffix) {
|
||||
String line = document.getText(lineRange);
|
||||
line = line.trim();
|
||||
int startOffset = Math.max(lineRange.getStartOffset(), commentRange.getStartOffset());
|
||||
int endOffset = Math.min(lineRange.getEndOffset(), commentRange.getEndOffset());
|
||||
|
||||
line = StringUtil.trimEnd(line, suffix);
|
||||
return StringUtil.trimStart(line, prefix);
|
||||
String commentPart = document.getText(new TextRange(startOffset, endOffset));
|
||||
|
||||
int suffixIdx = commentPart.indexOf(suffix);
|
||||
if (suffixIdx != -1) commentPart = commentPart.substring(0, suffixIdx).trim();
|
||||
|
||||
int prefixIdx = commentPart.indexOf(prefix);
|
||||
if (prefixIdx != -1) commentPart = commentPart.substring(prefixIdx + prefix.length());
|
||||
|
||||
return commentPart;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ class Test {
|
||||
void bar(char c) <fold text='{}'>{
|
||||
}</fold>
|
||||
|
||||
boolean b1 = true; <fold text='/** javadoc with code on the same line ...*/'>/** javadoc with code on the same line */</fold> boolean b2 = false; <fold text='/** second javadoc with code on the same line ...*/'>/** second javadoc with code on the same line */</fold>
|
||||
|
||||
<fold text='/** first line ...*/'>/** first line
|
||||
* second line
|
||||
*/</fold>
|
||||
|
||||
Reference in New Issue
Block a user