private static OffsetMap translateOffsetMapToInjected(
     OffsetMap hostMap, DocumentWindow injectedDocument) {
   final OffsetMap map = new OffsetMap(injectedDocument);
   for (final OffsetKey key : hostMap.getAllOffsets()) {
     map.addOffset(key, injectedDocument.hostToInjected(hostMap.getOffset(key)));
   }
   return map;
 }
  public static boolean isSelectionIsAboutToOverflowInjectedFragment(
      @NotNull EditorWindow injectedEditor) {
    int selStart = injectedEditor.getSelectionModel().getSelectionStart();
    int selEnd = injectedEditor.getSelectionModel().getSelectionEnd();

    DocumentWindow document = injectedEditor.getDocument();

    boolean isStartOverflows = selStart == 0;
    if (!isStartOverflows) {
      int hostPrev = document.injectedToHost(selStart - 1);
      isStartOverflows = document.hostToInjected(hostPrev) == selStart;
    }

    boolean isEndOverflows = selEnd == document.getTextLength();
    if (!isEndOverflows) {
      int hostNext = document.injectedToHost(selEnd + 1);
      isEndOverflows = document.hostToInjected(hostNext) == selEnd;
    }

    return isStartOverflows && isEndOverflows;
  }