public static @Nullable Pair<PsiFile, Editor> chooseBetweenHostAndInjected(
    @NotNull PsiFile hostFile,
    @NotNull Editor hostEditor,
    int hostOffset,
    @Nullable PsiFile injectedFile,
    @NotNull TripleFunction<? super @NotNull PsiFile, ? super @NotNull Editor, ? super @NotNull Integer, @NotNull Boolean> predicate) {
    try {
      Editor editorToApply = null;
      PsiFile fileToApply = null;

      if (injectedFile != null && !(hostEditor instanceof IntentionPreviewEditor)) {
        Editor injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(hostEditor, injectedFile);
        if (hostEditor != injectedEditor && injectedEditor instanceof EditorWindow editorWindow) {
          int injectedOffset = injectedEditor.logicalPositionToOffset(
            editorWindow.hostToInjected(hostEditor.offsetToLogicalPosition(hostOffset)));
          if (predicate.fun(injectedFile, injectedEditor, injectedOffset)) {
            editorToApply = injectedEditor;
            fileToApply = injectedFile;
          }
        }
      }

      if (editorToApply == null && predicate.fun(hostFile, hostEditor, hostOffset)) {
        editorToApply = hostEditor;
        fileToApply = hostFile;
      }
      if (editorToApply == null) return null;
      return Pair.create(fileToApply, editorToApply);
    }
    catch (IntentionPreviewUnsupportedOperationException e) {
      if (ApplicationManager.getApplication().isUnitTestMode()) {
        throw e;
      }
      return null;
    }
  }
public static @Nullable Pair<PsiFile, Editor> chooseBetweenHostAndInjected(
    @NotNull PsiFile hostFile,
    @NotNull Editor hostEditor,
    int hostOffset,
    @Nullable PsiFile injectedFile,
    @NotNull TripleFunction<? super @NotNull PsiFile, ? super @NotNull Editor, ? super @NotNull Integer, @NotNull Boolean> predicate)