@Override
  public @NotNull Result charTyped(char c, @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
    if (file.getFileType() == TextMateFileType.INSTANCE) {
      if (c == '\'' || c == '"' || c == '`') {
        if (!CodeInsightSettings.getInstance().AUTOINSERT_PAIR_QUOTE) {
          return Result.CONTINUE;
        }
      }
      else if (!CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET) {
        return Result.CONTINUE;
      }

      final int offset = editor.getCaretModel().getOffset();
      @Nullable TextMateScope scopeSelector = TextMateEditorUtils.getCurrentScopeSelector((EditorEx)editor);
      CharSequence sequence = editor.getDocument().getCharsSequence();
      final TextMateAutoClosingPair autoInsertingPair = findAutoInsertingPair(offset, sequence, scopeSelector);
      if (autoInsertingPair != null) {
        int rightBraceEndOffset = offset + autoInsertingPair.getRight().length();
        // has a right brace already
        if (rightBraceEndOffset < sequence.length() &&
            StringUtil.equals(autoInsertingPair.getRight(), sequence.subSequence(offset, rightBraceEndOffset))) {
          return Result.CONTINUE;
        }
        if (StringUtil.equals(autoInsertingPair.getLeft(), autoInsertingPair.getRight())) {
          // letter on the right
          if (offset < sequence.length() && Character.isLetterOrDigit(sequence.charAt(offset))) {
            return Result.CONTINUE;
          }
          int leftBraceStartOffset = offset - autoInsertingPair.getLeft().length();
          // letter on the left
          if (leftBraceStartOffset > 0 && Character.isLetterOrDigit(sequence.charAt(leftBraceStartOffset - 1))) {
            return Result.CONTINUE;
          }
        }
        EditorModificationUtilEx.insertStringAtCaret(editor, autoInsertingPair.getRight().toString(), true, false);
        return Result.STOP;
      }
    }
    return Result.CONTINUE;
  }
@Override
  public @NotNull Result charTyped(char c, @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file)