IDEA-62830 AE at com.intellij.openapi.editor.impl.softwrap.mapping.SoftWrapApplianceManager.a

1. Ensuring that collapsed fold region may be soft wrapped all the time;
2. Corresponding test is added;
This commit is contained in:
Denis Zhdanov
2010-12-13 12:08:38 +03:00
parent 2933526e62
commit e7cb7f66ce
2 changed files with 31 additions and 6 deletions
@@ -249,9 +249,14 @@ public class SoftWrapApplianceManager implements FoldingListener, DocumentListen
myContext.logicalLineData.update(foldRegion.getStartOffset());
SoftWrap softWrap = registerSoftWrap(
myContext.softWrapStartOffset, myContext.tokenStartOffset, myContext.tokenStartOffset, myContext.getSpaceWidth(), myContext.logicalLineData
myContext.softWrapStartOffset, myContext.tokenStartOffset, myContext.tokenStartOffset, myContext.getSpaceWidth(),
myContext.logicalLineData
);
assert softWrap != null; // We expect that it's always possible to wrap collapsed fold region placeholder text
if (softWrap == null) {
// If we're here that means that we can't find appropriate soft wrap offset before the fold region.
// However, we expect that it's always possible to wrap collapsed fold region placeholder text
softWrap = registerSoftWrap(myContext.tokenStartOffset, myContext.getSpaceWidth(), myContext.logicalLineData);
}
myContext.softWrapStartOffset = softWrap.getStart();
if (softWrap.getStart() < myContext.tokenStartOffset) {
revertListeners(softWrap.getStart(), myContext.currentPosition.visualLine);
@@ -524,19 +529,24 @@ public class SoftWrapApplianceManager implements FoldingListener, DocumentListen
return null;
}
return registerSoftWrap(softWrapOffset, spaceSize, lineData);
}
@NotNull
private SoftWrap registerSoftWrap(int offset, int spaceSize, LogicalLineData lineData) {
int indentInColumns = 0;
int indentInPixels = myPainter.getMinDrawingWidth(SoftWrapDrawingType.AFTER_SOFT_WRAP);
if (myCustomIndentUsedLastTime) {
indentInColumns = myCustomIndentValueUsedLastTime + lineData.indentInColumns;
indentInPixels += lineData.indentInPixels + (myCustomIndentValueUsedLastTime * spaceSize);
}
SoftWrapImpl softWrap = new SoftWrapImpl(
new TextChangeImpl("\n" + StringUtil.repeatSymbol(' ', indentInColumns), softWrapOffset, softWrapOffset),
SoftWrapImpl result = new SoftWrapImpl(
new TextChangeImpl("\n" + StringUtil.repeatSymbol(' ', indentInColumns), offset, offset),
indentInColumns + 1/* for 'after soft wrap' drawing */,
indentInPixels
);
myStorage.storeOrReplace(softWrap, true);
return softWrap;
myStorage.storeOrReplace(result, true);
return result;
}
/**
@@ -420,6 +420,21 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorP
assertEquals(startOffset, myEditor.logicalPositionToOffset(myEditor.visualToLogicalPosition(new VisualPosition(2, 0))));
}
public void testFoldRegionThatStartsAtLineEnd() throws IOException {
String text =
"line1\n" +
"line2\n" +
"line3\n" +
"line4\n" +
"line5";
init(30, text);
int start = text.indexOf("line3") - 1;
addCollapsedFoldRegion(start, text.length(), "...");
assertEquals(1, getSoftWrapModel().getRegisteredSoftWraps().size());
assertEquals(start, getSoftWrapModel().getRegisteredSoftWraps().get(0).getStart());
}
public void testHomeProcessing() throws IOException {
String text =
"class Test {\n" +