void (@NotNull IntentionAction action, @Nullable Editor editor, @NotNull PsiFile file, int problemOffset) { IntentionFUSCollector.record(file.getProject(), action, file.getLanguage()); PsiElement elementToMakeWritable = action.getElementToMakeWritable(file); if (elementToMakeWritable != null && !FileModificationService.getInstance().preparePsiElementsForWrite(elementToMakeWritable)) { return; } SmartPsiFileRange originalOffset = null; if (editor != null && problemOffset >= 0) { originalOffset = SmartPointerManager.getInstance(file.getProject()) .createSmartPsiFileRangePointer(file, TextRange.from(editor.getCaretModel().getOffset(), 0)); editor.getCaretModel().moveToOffset(problemOffset); } try { if (action.startInWriteAction()) { WriteAction.run(() -> action.invoke(file.getProject(), editor, file)); } else { action.invoke(file.getProject(), editor, file); } } finally { if (originalOffset != null && originalOffset.getRange() != null && editor.getCaretModel().getOffset() == problemOffset && TemplateManager.getInstance(file.getProject()).getActiveTemplate(editor) == null) { editor.getCaretModel().moveToOffset(originalOffset.getRange().getStartOffset()); } } }