void () { FoldingGroup group = FoldingGroup.newGroup("test"); FoldRegion[] regions = new FoldRegion[3]; myModel.runBatchFoldingOperation(() -> { regions[0] = myModel.createFoldRegion(1, 4, "a", group, false); regions[1] = myModel.createFoldRegion(3, 4, "b", group, false); regions[2] = myModel.createFoldRegion(20, 30, "c", group, false); }); assertNotNull(regions[0]); assertNotNull(regions[1]); assertNotNull(regions[2]); runWriteCommand(() -> DocumentUtil.executeInBulk(getEditor().getDocument(), () -> { getEditor().getDocument().deleteString(1, 3); // make first two regions belong to the same interval tree node getEditor().getDocument().deleteString(1, 2); // invalidate regions })); assertFalse(regions[0].isValid()); assertFalse(regions[1].isValid()); assertTrue(regions[2].isValid()); List<FoldRegion> regionsInGroup = myModel.getGroupedRegions(group); assertEquals(Collections.singletonList(regions[2]), regionsInGroup); }