diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java index b71c7a01738b..11c045d12567 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java @@ -342,10 +342,18 @@ public class SoftWrapApplianceManager implements SoftWrapFoldingListener, Docume } myContext.logicalLineData.update(foldRegion.getStartOffset()); - SoftWrap softWrap = registerSoftWrap( - myContext.softWrapStartOffset, myContext.tokenStartOffset, myContext.tokenStartOffset, myContext.getSpaceWidth(), - myContext.logicalLineData - ); + + SoftWrap softWrap; + if (myContext.exceedsVisualEdge(myContext.currentPosition.x + myContext.reservedWidthInPixels)) { + softWrap = registerSoftWrap( + myContext.softWrapStartOffset, myContext.tokenStartOffset, myContext.tokenStartOffset, myContext.getSpaceWidth(), + myContext.logicalLineData + ); + } + else { + softWrap = registerSoftWrap(foldRegion.getStartOffset(), myContext.getSpaceWidth(), myContext.logicalLineData); + } + 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 @@ -524,10 +532,7 @@ public class SoftWrapApplianceManager implements SoftWrapFoldingListener, Docume EditorPosition wrapPosition = null; // Try to insert soft wrap after the last collapsed fold region that is located on the current visual line. - if (myContext.lastFoldEndPosition != null && myStorage.getSoftWrap(myContext.lastFoldEndPosition.offset) == null - && myContext.lastFoldEndPosition.offset + 1/* reserve one visual column for the soft wrap sign */ - < myContext.currentPosition.offset) - { + if (myContext.lastFoldEndPosition != null && myStorage.getSoftWrap(myContext.lastFoldEndPosition.offset) == null) { wrapPosition = myContext.lastFoldEndPosition; } @@ -637,10 +642,10 @@ public class SoftWrapApplianceManager implements SoftWrapFoldingListener, Docume } /** - * This method is assumed to be called in situation when visible area width is exceeded. It tries to create and register + * This method is assumed to be called in a situation when visible area width is exceeded. It tries to create and register * new soft wrap which data is defined in accordance with the given parameters. *
- * There is a possible case that no soft wrap is created and registered. That is true, for example, for situation when + * There is a possible case that no soft wrap is created and registered. That is true, for example, for a situation when * we have a long line of text that doesn't contain white spaces, operators or any other symbols that may be used * as a'wrap points'. We just left such lines as-is.
*
diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceOnDocumentModificationTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceOnDocumentModificationTest.java
index ed10dc32596d..92da108c7c29 100644
--- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceOnDocumentModificationTest.java
+++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceOnDocumentModificationTest.java
@@ -938,6 +938,20 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorP
checkSoftWraps(start, end);
}
+
+ public void testFoldRegionWithLongPlaceholderText() throws IOException {
+ final String text =
+ "this is a string with(fold region), end)\n" +
+ "second string";
+ init(40, text);
+
+ int start = text.indexOf("fold");
+ int end = text.indexOf(',');
+ addCollapsedFoldRegion(start, end, "this is a really long fold region placeholder");
+
+ checkSoftWraps(start, end);
+ assertEquals(new VisualPosition(3, 0), myEditor.offsetToVisualPosition(text.indexOf("second")));
+ }
private void init(final int visibleWidthInColumns, @NotNull String fileText) throws IOException {
int symbolWidthInPixels = 7;