FoldRegion (int startOffset, int endOffset, @NotNull String placeholder, FoldingGroup group, boolean neverExpands) { TextRange hostRange = myDocumentWindow.injectedToHost(new TextRange(startOffset, endOffset)); if (hostRange.getLength() < 2) return null; FoldRegion hostRegion = myDelegate.createFoldRegion(hostRange.getStartOffset(), hostRange.getEndOffset(), placeholder, group, neverExpands); if (hostRegion == null) return null; FoldingRegionWindow window = new FoldingRegionWindow(myDocumentWindow, myEditorWindow, startOffset, endOffset){ @Override @NotNull RangeMarker createHostRangeMarkerToTrack(@NotNull TextRange hostRange, boolean surviveOnExternalChange) { return hostRegion; } }; hostRegion.putUserData(FOLD_REGION_WINDOW, window); return window; }