diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java index 5dc22888ccd2..3a2996e92815 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java @@ -723,6 +723,7 @@ public class FoldingModelImpl extends InlayModel.SimpleAdapter FoldRegionImpl otherRegion = getRegion(otherNode); if (otherRegion.mySizeBeforeUpdate > region.mySizeBeforeUpdate) { setNode(region, null); + removeRegionFromGroup(region); removeIntervalInternal(0); super.addIntervalsFrom(otherNode); } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/FoldingTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/FoldingTest.java index 3ae75f036a95..dc4eb23490d2 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/FoldingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/FoldingTest.java @@ -398,4 +398,18 @@ public class FoldingTest extends AbstractEditorTest { FoldRegion region = addFoldRegion(0, 0, "."); assertNull(region); } + + public void testRegionBecomingInvalidIsRemovedFromGroup() { + FoldingGroup group = FoldingGroup.newGroup("test"); + + myEditor.getFoldingModel().runBatchFoldingOperation( + () -> myModel.createFoldRegion(0, 10, "...", group, false) + ); + addCollapsedFoldRegion(1, 10, "..."); + + WriteCommandAction.runWriteCommandAction(getProject(), () -> myEditor.getDocument().deleteString(0, 1)); + + List regions = myModel.getGroupedRegions(group); + assertEmpty(regions); + } }