void () { Document document = new DocumentImpl("\n\n\n"); MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(document, getProject(), true); RangeHighlighter h = model.addPersistentLineHighlighter(null, 2, 0); assertTrue(h.isValid()); assertEquals(2, h.getStartOffset()); assertEquals(2, h.getEndOffset()); WriteCommandAction.runWriteCommandAction(getProject(), () -> document.deleteString(0, 1)); assertTrue(h.isValid()); assertEquals(1, h.getStartOffset()); assertEquals(1, h.getEndOffset()); WriteCommandAction.runWriteCommandAction(getProject(), () -> document.replaceString(0, 2, " \n\n ")); assertTrue(h.isValid()); assertEquals(2, h.getStartOffset()); assertEquals(2, h.getEndOffset()); }