private static Context getContext(AnActionEvent e, boolean findOnly) {
    Editor editor = e.getData(CommonDataKeys.EDITOR);
    if (editor != null) {
      if (editor.isViewer()) return null;
      if (findOnly) return Context.FOUND;
      Consumer<String> input;
      if (editor instanceof EditorImpl) {
        input = ((EditorImpl)editor)::type;
      }
      else if (editor.getContentComponent() instanceof TypingTarget) {
        input = ((TypingTarget)editor.getContentComponent())::type;
      }
      else {
        input = s -> WriteCommandAction.writeCommandAction(editor.getProject()).run(() -> {
          com.intellij.openapi.editor.Document doc = editor.getDocument();
          editor.getCaretModel().runForEachCaret(c -> {
            doc.insertString(c.getOffset(), s);
            c.moveCaretRelatively(1, 0, false, false);
          });
        });
      }
      return new Context(input, p -> p.showInBestPositionFor(editor));
    }

    Component component = e.getData(PlatformCoreDataKeys.CONTEXT_COMPONENT);
    if (component instanceof EmojiSearchField) {
      // Easy way to block recursive pickers
      return null;
    }

    if (component instanceof TypingTarget) {
      if (findOnly) return Context.FOUND;
      return new Context(
        ((TypingTarget)component)::type,
        p -> p.showUnderneathOf(component)
      );
    }

    if (component instanceof JTextComponent field) {
      if (findOnly) return Context.FOUND;
      Document doc = field.getDocument();
      return new Context(
        s -> {
          try {
            doc.insertString(field.getCaretPosition(), s, null);
          }
          catch (BadLocationException exception) {
            throw new RuntimeException(exception);
          }
        },
        p -> p.showUnderneathOf(component)
      );
    }

    return null;
  }
private static Context getContext(AnActionEvent e, boolean findOnly)