private static void copyCaretPosition(@NotNull Editor destination, Editor source, Function<? super String, String> mapper) {
    if (source == null) return; // unexpected
    try {
      List<CaretState> states = source.getCaretModel().getCaretsAndSelections();
      if (!mapper.equals(Functions.identity())) {
        states = extractStates(mapper.fun(injectStates(source.getDocument().getText(), states)));
      }
      destination.getCaretModel().setCaretsAndSelections(states);
    }
    catch (IllegalArgumentException ignored) {
    }
  }
private static void copyCaretPosition(@NotNull Editor destination, Editor source, Function<? super String, String> mapper)