void () { // There was incorrect processing of fold regions when document change was performed right before them. String text = """ /** * comment */ class Test { }"""; init(100, text); String placeholder = "/**...*/"; addCollapsedFoldRegion(0, text.indexOf("class") - 1, placeholder); getEditor().getCaretModel().moveToOffset(0); type("\n"); getEditor().getCaretModel().moveToOffset(0); type("import"); // Check that fold region info is still correct. int foldStartOffset = getEditor().getDocument().getText().indexOf("/**"); int foldEndOffset = getEditor().getDocument().getText().indexOf("class") - 1; assertEquals(new VisualPosition(1, 0), getEditor().offsetToVisualPosition(foldStartOffset)); assertEquals(new VisualPosition(1, 0), getEditor().offsetToVisualPosition((foldStartOffset + foldEndOffset) / 2)); assertEquals(new VisualPosition(1, placeholder.length()), getEditor().offsetToVisualPosition(foldEndOffset)); }