void () { initText("abcdef"); Document document = getEditor().getDocument(); document.addDocumentListener(new DocumentListener() { @Override public void bulkUpdateFinished(@NotNull Document document) { getEditor().getMarkupModel().addRangeHighlighter(null, 7, 8, 0, HighlighterTargetArea.EXACT_RANGE); } }, getTestRootDisposable()); runWriteCommand(() -> DocumentUtil.executeInBulk(document, ()-> document.insertString(3, "\n\n"))); RangeHighlighter[] highlighters = getEditor().getMarkupModel().getAllHighlighters(); assertEquals(1, highlighters.length); assertEquals(7, highlighters[0].getStartOffset()); assertEquals(8, highlighters[0].getEndOffset()); }