DocumentFragment (@NotNull FoldRegion fold) { final FoldingGroup group = fold.getGroup(); final int foldStart = fold.getStartOffset(); if (group != null) { final int endOffset = myFoldingModel.getEndOffset(group); if (offsetToVisualLine(endOffset) == offsetToVisualLine(foldStart)) { return new DocumentFragment(myDocument, foldStart, endOffset); } } final int oldEnd = fold.getEndOffset(); return new DocumentFragment(myDocument, foldStart, oldEnd); }