ActionContext (@NotNull PsiFile hostFile, @Nullable Editor hostEditor, @NotNull ModCommandAction commandAction) { if (hostEditor == null) { return ActionContext.from(null, hostFile); } PsiFile injectedFile = InjectedLanguageUtilBase.findInjectedPsiNoCommit(hostFile, hostEditor.getCaretModel().getOffset()); Editor injectedEditor = null; if (injectedFile != null && !(hostEditor instanceof IntentionPreviewEditor)) { injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(hostEditor, injectedFile); ActionContext injectedContext = ActionContext.from(injectedEditor, injectedFile); if (commandAction.getPresentation(injectedContext) != null) { return injectedContext; } } if (hostEditor != injectedEditor) { ActionContext hostContext = ActionContext.from(hostEditor, hostFile); if (commandAction.getPresentation(hostContext) != null) { return hostContext; } } return null; }