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,44 +1205,55 @@ 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 {
// if comment starts at column 0 and spans only one line singleLine= true;
// and is adjacent to a previous line comment, add it }
// to the commentRange } else {
int lineNr = doc.getLineOfOffset(partition.getOffset()); singleLine= ICPartitions.C_SINGLE_LINE_COMMENT.equals(partition.getType());
IRegion lineRegion = doc.getLineInformation(lineNr); }
boolean isLineStart = partition.getOffset() == lineRegion.getOffset(); if (singleLine) {
if (!isLineStart) { // if comment starts at column 0 and spans only one line
// and is adjacent to a previous line comment, add it
// to the commentRange
int lineNr = doc.getLineOfOffset(partition.getOffset());
IRegion lineRegion = doc.getLineInformation(lineNr);
boolean isLineStart = partition.getOffset() == lineRegion.getOffset();
if (!isLineStart) {
continue;
}
if (!singleLine) {
singleLine = lineRegion.getOffset() + lineRegion.getLength() >= partition.getOffset() + partition.getLength();
if (!singleLine) {
continue; continue;
} }
if (!singleLine) { }
singleLine = lineRegion.getOffset() + lineRegion.getLength() >= partition.getOffset() + partition.getLength(); if (startLine < 0 || lineNr - endLine > 1) {
if (!singleLine) { if (startLine >= 0 && endLine - startLine >= fMinCommentLines) {
continue; 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));
} }
} }
if (startLine < 0 || lineNr - endLine > 1) { startLine = lineNr;
if (startLine >= 0 && endLine - startLine >= fMinCommentLines) { endLine = lineNr;
Position projection = createCommentPosition(alignRegion(commentRange, ctx)); commentRange.offset = lineRegion.getOffset();
if (projection != null) { commentRange.length = lineRegion.getLength();
comments.add(new Tuple(new CProjectionAnnotation(collapse, doc.get(projection.offset, Math.min(16, projection.length)), true), projection)); } else {
} endLine = lineNr;
} int delta = lineRegion.getOffset() + lineRegion.getLength() - commentRange.offset - commentRange.length;
startLine = lineNr; commentRange.length += delta;
endLine = lineNr;
commentRange.offset = lineRegion.getOffset();
commentRange.length = lineRegion.getLength();
} else {
endLine = lineNr;
int delta = lineRegion.getOffset() + lineRegion.getLength() - commentRange.offset - commentRange.length;
commentRange.length += delta;
}
} }
} }
} }
@ -1253,13 +1264,16 @@ 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();
if (ctx.collapseHeaderComments()) { int lineNr = doc.getLineOfOffset(tuple.position.getOffset());
tuple.annotation.markCollapsed(); if (lineNr < 10) {
} else { if (ctx.collapseHeaderComments()) {
tuple.annotation.markExpanded(); tuple.annotation.markCollapsed();
} else {
tuple.annotation.markExpanded();
}
} }
ctx.addProjectionRange(tuple.annotation, tuple.position); ctx.addProjectionRange(tuple.annotation, tuple.position);
while (iter.hasNext()) { while (iter.hasNext()) {