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