1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix initial collapse state of header comments

This commit is contained in:
Anton Leherbauer 2006-09-27 12:47:06 +00:00
parent 444e2e32ab
commit 120526e448

View file

@ -1205,13 +1205,25 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
ModifiableRegion commentRange = new ModifiableRegion(); ModifiableRegion commentRange = new ModifiableRegion();
for (int i = 0; i < partitions.length; i++) { for (int i = 0; i < partitions.length; i++) {
ITypedRegion partition = partitions[i]; ITypedRegion partition = partitions[i];
// TLETODO [folding] add support for Cppdoc comment? boolean singleLine= false;
boolean singleLine = ICPartitions.C_SINGLE_LINE_COMMENT.equals(partition.getType()); if (ICPartitions.C_MULTI_LINE_COMMENT.equals(partition.getType())) {
if (singleLine || ICPartitions.C_MULTI_LINE_COMMENT.equals(partition.getType())) { Position position= createCommentPosition(alignRegion(partition, ctx));
Position position= singleLine ? null : createCommentPosition(alignRegion(partition, ctx));
if (position != null) { if (position != null) {
if (startLine >= 0 && endLine - startLine >= fMinCommentLines) {
Position projection = createCommentPosition(alignRegion(commentRange, ctx));
if (projection != null) {
comments.add(new Tuple(new CProjectionAnnotation(collapse, doc.get(projection.offset, Math.min(16, projection.length)), true), projection));
}
startLine= -1;
}
comments.add(new Tuple(new CProjectionAnnotation(collapse, doc.get(position.offset, Math.min(16, position.length)), true), position)); comments.add(new Tuple(new CProjectionAnnotation(collapse, doc.get(position.offset, Math.min(16, position.length)), true), position));
} else { } else {
singleLine= true;
}
} else {
singleLine= ICPartitions.C_SINGLE_LINE_COMMENT.equals(partition.getType());
}
if (singleLine) {
// if comment starts at column 0 and spans only one line // if comment starts at column 0 and spans only one line
// and is adjacent to a previous line comment, add it // and is adjacent to a previous line comment, add it
// to the commentRange // to the commentRange
@ -1245,7 +1257,6 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
} }
} }
} }
}
if (startLine >= 0 && endLine - startLine >= fMinCommentLines) { if (startLine >= 0 && endLine - startLine >= fMinCommentLines) {
Position projection = createCommentPosition(alignRegion(commentRange, ctx)); Position projection = createCommentPosition(alignRegion(commentRange, ctx));
if (projection != null) { if (projection != null) {
@ -1253,14 +1264,17 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
} }
} }
if (!comments.isEmpty()) { if (!comments.isEmpty()) {
// first comment is header comment // first comment starting before line 10 is considered the header comment
Iterator iter = comments.iterator(); Iterator iter = comments.iterator();
Tuple tuple = (Tuple) iter.next(); Tuple tuple = (Tuple) iter.next();
int lineNr = doc.getLineOfOffset(tuple.position.getOffset());
if (lineNr < 10) {
if (ctx.collapseHeaderComments()) { if (ctx.collapseHeaderComments()) {
tuple.annotation.markCollapsed(); tuple.annotation.markCollapsed();
} else { } else {
tuple.annotation.markExpanded(); tuple.annotation.markExpanded();
} }
}
ctx.addProjectionRange(tuple.annotation, tuple.position); ctx.addProjectionRange(tuple.annotation, tuple.position);
while (iter.hasNext()) { while (iter.hasNext()) {
tuple = (Tuple) iter.next(); tuple = (Tuple) iter.next();