<commit_before>/* global NAME_CONTROLLER, DIRECTION_NEXT, DIRECTION_PREVIOUS, KEY_DOWN */
/* global KEY_UP, KEY_RIGHT, KEY_LEFT, PAGE_SIZE_DEFAULT, SCROLL_BUFFER, CLOSE_EVENT */
/* global OPEN_EVENT, NAME_FONTSSERVICE */
var NAME_JDFONTLIST = 'jdFontlist';
var NAME_JDFONTLIST_CONTROLLER = NAME_JDFONTLIST + NAME_CONTROLLER;

fontselectModule.directive(NAME_JDFONTLIST, function() {
  return {
    scope: {
      id: '=fsid',
      fonts: '=',
      meta: '=',
      current: '=',
      text: '=',
      active: '='
    },
    restrict: 'E',
    templateUrl: 'fontlist.html',
    replace: true,
    controller: NAME_JDFONTLIST_CONTROLLER
  };
});

fontselectModule.controller(NAME_JDFONTLIST_CONTROLLER, [
  '$scope',
  '$rootScope',
  '$filter',
  NAME_FONTSSERVICE,
  '$element',
  '$document',
  /* jshint maxparams: 6 */
  function($scope, $rootScope, $filter, fontsService, $element, $document) {
  /* jshint maxparams: 3 */
    var _filteredFonts = [];
    var _sortedFonts = [];
    var _searchedFonts = [];
    var _categorizedFonts = [];
    var _fontsInSubsets = [];
    var _fontsInProviders = [];
    var _lastPageCount = 0;
    var _sortCache = {};
    var _scrollBuffer = 0;
    var _forceNextFilters = false;


    var page = $scope.page = $scope.meta.page = {
      size: PAGE_SIZE_DEFAULT,
      count: 0,
      current: 0,
      currentAbs: 0
    };
    var fontmeta = $scope.meta.fonts = {
      total: 0,
      current: 0
    };

    function isOnCurrentPage(index) {
      var currentMinIndex = page.current * page.size;

      return index >= currentMinIndex && index < currentMinIndex + page.size;
    }

    $scope.keyfocus = function(direction, amount) {
      var index = _filteredFonts.indexOf($scope.current.font);
      var pageoffset = page.size * page.current;
      var onPage = isOnCurrentPage(index);

      if (angular.isUndefined(amount)) {
        amount = 1;
      }

      index += (direction === DIRECTION_PREVIOUS ? -amount : amount);

      if (!onPage && _filteredFonts[index + pageoffset]) {
        index += pageoffset;
      }

      if (_filteredFonts[index]) {
        $scope.current.font = _filteredFonts[index];

        page.currentAbs = page.current = Math.floor(index / page.size);

        $rootScope.$digest();
      }
    };

    function keyDownHandler(event) {
      if (!$scope.active) {
        return;
      }

      function prevent() {
        event.preventDefault();
        return false;
      }

      var key = event.keyCode;

      if (key === KEY_DOWN) {
        $scope.keyfocus(DIRECTION_NEXT);
        return prevent();
      } else if (key === KEY_UP) {
        $scope.keyfocus(DIRECTION_PREVIOUS);
        return prevent();
      }

      if (document.activeElement.tagName === 'INPUT' && document.activeElement.value) {
        return;
      }

      var amount = page.size;
      if (key === KEY_RIGHT) {
        if (!$scope.current.font) {
          amount++;
        }
        $scope.keyfocus(DIRECTION_NEXT, amount);
        return prevent();
      } else if (key === KEY_LEFT) {
        $scope.keyfocus(DIRECTION_PREVIOUS, page.size);
        return prevent();
      }
    }

    function getDeltaFromEvent(event) {
      var delta = event.wheelDeltaY || event.wheelDelta ||
        event.deltaY * -1 || event.detail * -1;

      if (angular.isUndefined(delta) &&
        !angular.isUndefined(event.originalEvent)) {
        delta = getDeltaFromEvent(event.originalEvent);
      }

      return delta;
    }

    var wheelHandler = function(event) {
      if (!event.target) {
        return;
      }

      if (_isDescendant($element[0], event.target)) {
        event.preventDefault();<commit_msg>fix(fontlist): check for finite instead of undefined<commit_after>/* global NAME_CONTROLLER, DIRECTION_NEXT, DIRECTION_PREVIOUS, KEY_DOWN */
/* global KEY_UP, KEY_RIGHT, KEY_LEFT, PAGE_SIZE_DEFAULT, SCROLL_BUFFER, CLOSE_EVENT */
/* global OPEN_EVENT, NAME_FONTSSERVICE */
var NAME_JDFONTLIST = 'jdFontlist';
var NAME_JDFONTLIST_CONTROLLER = NAME_JDFONTLIST + NAME_CONTROLLER;

fontselectModule.directive(NAME_JDFONTLIST, function() {
  return {
    scope: {
      id: '=fsid',
      fonts: '=',
      meta: '=',
      current: '=',
      text: '=',
      active: '='
    },
    restrict: 'E',
    templateUrl: 'fontlist.html',
    replace: true,
    controller: NAME_JDFONTLIST_CONTROLLER
  };
});

fontselectModule.controller(NAME_JDFONTLIST_CONTROLLER, [
  '$scope',
  '$rootScope',
  '$filter',
  NAME_FONTSSERVICE,
  '$element',
  '$document',
  /* jshint maxparams: 6 */
  function($scope, $rootScope, $filter, fontsService, $element, $document) {
  /* jshint maxparams: 3 */
    var _filteredFonts = [];
    var _sortedFonts = [];
    var _searchedFonts = [];
    var _categorizedFonts = [];
    var _fontsInSubsets = [];
    var _fontsInProviders = [];
    var _lastPageCount = 0;
    var _sortCache = {};
    var _scrollBuffer = 0;
    var _forceNextFilters = false;


    var page = $scope.page = $scope.meta.page = {
      size: PAGE_SIZE_DEFAULT,
      count: 0,
      current: 0,
      currentAbs: 0
    };
    var fontmeta = $scope.meta.fonts = {
      total: 0,
      current: 0
    };

    function isOnCurrentPage(index) {
      var currentMinIndex = page.current * page.size;

      return index >= currentMinIndex && index < currentMinIndex + page.size;
    }

    $scope.keyfocus = function(direction, amount) {
      var index = _filteredFonts.indexOf($scope.current.font);
      var pageoffset = page.size * page.current;
      var onPage = isOnCurrentPage(index);

      if (angular.isUndefined(amount)) {
        amount = 1;
      }

      index += (direction === DIRECTION_PREVIOUS ? -amount : amount);

      if (!onPage && _filteredFonts[index + pageoffset]) {
        index += pageoffset;
      }

      if (_filteredFonts[index]) {
        $scope.current.font = _filteredFonts[index];

        page.currentAbs = page.current = Math.floor(index / page.size);

        $rootScope.$digest();
      }
    };

    function keyDownHandler(event) {
      if (!$scope.active) {
        return;
      }

      function prevent() {
        event.preventDefault();
        return false;
      }

      var key = event.keyCode;

      if (key === KEY_DOWN) {
        $scope.keyfocus(DIRECTION_NEXT);
        return prevent();
      } else if (key === KEY_UP) {
        $scope.keyfocus(DIRECTION_PREVIOUS);
        return prevent();
      }

      if (document.activeElement.tagName === 'INPUT' && document.activeElement.value) {
        return;
      }

      var amount = page.size;
      if (key === KEY_RIGHT) {
        if (!$scope.current.font) {
          amount++;
        }
        $scope.keyfocus(DIRECTION_NEXT, amount);
        return prevent();
      } else if (key === KEY_LEFT) {
        $scope.keyfocus(DIRECTION_PREVIOUS, page.size);
        return prevent();
      }
    }

    function getDeltaFromEvent(event) {
      var delta = event.wheelDeltaY || event.wheelDelta ||
        event.deltaY * -1 || event.detail * -1;

      if (!isFinite(delta) &&
        !angular.isUndefined(event.originalEvent)) {
        delta = getDeltaFromEvent(event.originalEvent);
      }

      return delta;
    }

    var wheelHandler = function(event) {
      if (!event.target) {
        return;
      }

      if (_isDescendant($element[0], event.target)) {
        event.preventDefault();
{'fraction_non_alphanumeric': 0.13202437373053486, 'fraction_numerical': 0.0035206499661475966, 'mean_word_length': 2.4872521246458925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2202194', 'n_tokens_mistral': 2449, 'n_tokens_neox': 2358, 'n_words': 467}