void () { initText("line1\nline2\nline3"); FoldingModelEx model = (FoldingModelEx)getEditor().getFoldingModel(); AtomicInteger invocationCount = new AtomicInteger(); model.addListener(new FoldingListener() { @Override public void beforeFoldRegionDisposed(@NotNull FoldRegion region) { invocationCount.incrementAndGet(); } }, getTestRootDisposable()); FoldRegion region = addFoldRegion(0, 17, "."); assertNotNull(region); assertTrue(region.isValid()); CustomFoldRegion customRegion = addCustomFoldRegion(1, 1); assertNotNull(customRegion); assertTrue(customRegion.isValid()); assertEquals(0, invocationCount.get()); runWriteCommand(() -> getEditor().getDocument().deleteString(11, 17)); assertTrue(region.isValid()); assertFalse(customRegion.isValid()); assertEquals(1, invocationCount.get()); }