<commit_before>// jshint camelcase: false
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers

(function() {
  'use strict';

  var app = angular.module('radar.ui');

  app.directive('textEditor', ['tinymce', '$sce', function(tinymce, $sce) {
    var nextId = 0;

    return {
      restrict: 'A',
      require: 'ngModel',
      link: function(scope, element, attrs, ngModel) {
        var instance;

        var id = 'text-editor-' + nextId++;
        attrs.$set('id', id);

        ngModel.$render = function() {
          var instance = getInstance();

          if (instance) {
            var viewValue = ngModel.$viewValue;
            viewValue = viewValue ? $sce.getTrustedHtml(viewValue) : '';
            instance.setContent(viewValue);
            instance.fire('change');
          }
        };

        ngModel.$formatters.unshift(function(modelValue) {
          return modelValue ? $sce.trustAsHtml(modelValue) : '';
        });

        ngModel.$parsers.unshift(function(viewValue) {
          return viewValue ? $sce.getTrustedHtml(viewValue) : '';
        });

        scope.$on('$destroy', function() {
          var instance = getInstance();

          if (instance) {
            instance.remove();
            instance = null;
          }
        });

        tinymce.init({
          selector: '#' + id,
          menubar: false,
          toolbar: 'bold italic | link unlink | bullist numlist | code',
          valid_elements: 'a[href|target=_blank],br,em,li,ol,p,strong,ul',
          plugins: ['link', 'code'],
          setup: function(editor) {
            editor.on('init', function() {
              ngModel.$render();
              ngModel.$setPristine();
            });

            editor.on('keyup', function() {
              updateView(editor);
            });

            // Content changed using toolbar buttons
            editor.on('change', function() {
              updateView(editor);
            });
          }
        });

        function getInstance() {
          if (!instance) {
            instance = tinymce.get(id);
          }

          return instance;
        }

        function updateView(editor) {
          var content = editor.getContent().trim();
          content = $sce.trustAsHtml(content);
          ngModel.$setViewValue(content);
          scope.$apply();
        }
      }
    };
  }]);
})();
<commit_msg>Make sure form is pristine after init<commit_after>// jshint camelcase: false
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers

(function() {
  'use strict';

  var app = angular.module('radar.ui');

  app.directive('textEditor', ['tinymce', '$sce', function(tinymce, $sce) {
    var nextId = 0;

    return {
      restrict: 'A',
      require: ['ngModel', '?^form'],
      link: function(scope, element, attrs, ctrls) {
        var ngModelCtrl = ctrls[0];
        var formCtrl = ctrls[1];

        var instance;

        var id = 'text-editor-' + nextId++;
        attrs.$set('id', id);

        ngModelCtrl.$render = function() {
          var instance = getInstance();

          if (instance) {
            var viewValue = ngModelCtrl.$viewValue;
            viewValue = viewValue ? $sce.getTrustedHtml(viewValue) : '';
            instance.setContent(viewValue);
            instance.fire('change');
          }
        };

        ngModelCtrl.$formatters.unshift(function(modelValue) {
          return modelValue ? $sce.trustAsHtml(modelValue) : '';
        });

        ngModelCtrl.$parsers.unshift(function(viewValue) {
          return viewValue ? $sce.getTrustedHtml(viewValue) : '';
        });

        scope.$on('$destroy', function() {
          var instance = getInstance();

          if (instance) {
            instance.remove();
            instance = null;
          }
        });

        tinymce.init({
          selector: '#' + id,
          menubar: false,
          toolbar: 'bold italic | link unlink | bullist numlist | code',
          valid_elements: 'a[href|target=_blank],br,em,li,ol,p,strong,ul',
          plugins: ['link', 'code'],
          setup: function(editor) {
            editor.on('init', function() {
              ngModelCtrl.$render();
              ngModelCtrl.$setPristine();

              if (formCtrl) {
                formCtrl.$setPristine();
              }

              scope.$apply();
            });

            editor.on('keyup', function() {
              updateView(editor);
            });

            // Content changed using toolbar buttons
            editor.on('change', function() {
              updateView(editor);
            });
          }
        });

        function getInstance() {
          if (!instance) {
            instance = tinymce.get(id);
          }

          return instance;
        }

        function updateView(editor) {
          var content = editor.getContent().trim();
          content = $sce.trustAsHtml(content);
          ngModelCtrl.$setViewValue(content);
          scope.$apply();
        }
      }
    };
  }]);
})();

{'fraction_non_alphanumeric': 0.14092086904524617, 'fraction_numerical': 0.0007972892166633447, 'mean_word_length': 1.7405789186237028, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6522154', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1385, 'n_words': 263}