private static void handleUserSelection(InsertionContext context, @NotNull Function<? super Color, String> colorToStringConverter) {
    Project project = context.getProject();
    Editor editor = context.getEditor();
    int startOffset = context.getStartOffset();

    context.getDocument().deleteString(startOffset, context.getTailOffset());
    PsiElement element = context.getFile().findElementAt(editor.getCaretModel().getOffset());
    Color myColorAtCaret = element instanceof XmlToken ? getColorFromElement(element) : null;

    context.setLaterRunnable(() -> {
      if (editor.isDisposed() || project.isDisposed()) return;
      List<ColorPickerListener> listeners = ColorPickerListenerFactory.createListenersFor(element);
      Color color = ColorChooserService.getInstance().showDialog(project, WindowManager.getInstance().suggestParentWindow(project),
                                                                 IdeBundle.message("dialog.title.choose.color"), myColorAtCaret, true, listeners, true);
      if (color != null) {
        WriteCommandAction.runWriteCommandAction(project, () -> {
          editor.getCaretModel().moveToOffset(startOffset);
          EditorModificationUtil.insertStringAtCaret(editor, colorToStringConverter.fun(color));
        });
      }
    });
  }
private static void handleUserSelection(InsertionContext context, @NotNull Function<? super Color, String> colorToStringConverter)