void () { String text = "a\n#%%\nc"; // ^^^^^^^ <- guarded // com.intellij.openapi.editor.actions.DocumentGuardedTextUtil.insertString handles this case and inserts "\na" after first "a" myFixture.configureByText("x.txt", text); RangeMarker guard = createGuard(1, 6); myFixture.performEditorAction(IdeActions.ACTION_EDITOR_DUPLICATE_LINES); myFixture.checkResult("a\na\n#%%\nc"); assertTrue(guard.isValid()); assertEquals(3, guard.getStartOffset()); assertEquals(8, guard.getEndOffset()); }