private static int getClosestTargetOffset(@NotNull Editor editor, @NotNull PsiFile file) {
      int offsetFromBraceMatcher = getOffsetFromBraceMatcher(editor, file);
      TextRange rangeFromCodeBlockSupport = CodeBlockSupportHandler.findCodeBlockRange(editor, file);
      if (rangeFromCodeBlockSupport.isEmpty() || rangeFromCodeBlockSupport.contains(offsetFromBraceMatcher)) {
        return offsetFromBraceMatcher;
      }

      final EditorHighlighter highlighter = editor.getHighlighter();
      int caretOffset = editor.getCaretModel().getOffset();
      HighlighterIterator iterator = highlighter.createIterator(caretOffset);

      // end of file or at block closing token
      if (iterator.atEnd() || iterator.getEnd() == rangeFromCodeBlockSupport.getEndOffset() ||
          // edge case - end of closing token
          (caretOffset > 0 && highlighter.createIterator(caretOffset - 1).getEnd() == rangeFromCodeBlockSupport.getEndOffset())) {
        return rangeFromCodeBlockSupport.getStartOffset();
      }
      return rangeFromCodeBlockSupport.getEndOffset();
    }
private static int getClosestTargetOffset(@NotNull Editor editor, @NotNull PsiFile file)