void () { final Document document = myEditor.getDocument(); if (!mySelectionRangeMarker.isValid()) return; final int start = mySelectionRangeMarker.getStartOffset(); final int end = mySelectionRangeMarker.getEndOffset(); WriteCommandAction.writeCommandAction(myProject) .withName(LangBundle.message("command.name.configure.code.style.on.selected.fragment.restore.text.before")) .run(() -> document.replaceString(start, end, myTextBefore)); myEditor.getSelectionModel().setSelection(start, start + myTextBefore.length()); }