<commit_before>'use strict'

angular.module('serinaApp').directive('toolbar', function ($timeout) {
  return {
    restrict: 'E',
    templateUrl: 'views/commons/toolbar.html',
    link: function (scope) {

      scope.search = null

      var clearMatchingElements = function () {
        scope.matchingElements = []
      }

      scope.initiateSearch = function () {
        scope.search = ''
        $timeout(function () {
          document.getElementById('search-input').focus()
        }, 10)
        clearMatchingElements()
      }

      scope.showPreSearchBar = function () {
        return scope.search === null
      }

      scope.endSearch = function () {
        scope.search = null
        clearMatchingElements()
        scope.currentMatchingElement = 0
      }

      scope.searchKey = function () {
        if (scope.search !== '') {
          var inputKeys = document.querySelectorAll('translation md-card .key')
          scope.matchingElements = []
          scope.currentMatchingElement = 0
          for (var iterator = 0; iterator < inputKeys.length; iterator++) {
            if (inputKeys[iterator].value.toLowerCase().indexOf(scope.search.toLowerCase()) !== -1) {
              scope.matchingElements.push(inputKeys[iterator])
            }
          }

          if (scope.matchingElements.length === 0) {
            scope.endSearch()
          } else {
            scope.matchingElements[0].focus()
          }
        }
      }

      scope.navigateBetweenMatchingElements = function (sign) {
        if (sign === '-' || sign === '+') {
          if (sign === '-') {
            scope.currentMatchingElement--
            if (scope.currentMatchingElement < 0) {
              scope.currentMatchingElement = scope.matchingElements.length - 1
            }
          } else if (sign === '+') {
            scope.currentMatchingElement++
            if (scope.currentMatchingElement > scope.matchingElements.length - 1) {
              scope.currentMatchingElement = 0
            }
          }
          scope.matchingElements[scope.currentMatchingElement].focus()
        }
      }

      Mousetrap.bindGlobal('ctrl+up', function () {
        if (scope.matchingElements) {
          scope.navigateBetweenMatchingElements('-')
        }
      })

      Mousetrap.bindGlobal('ctrl+down', function () {
        if (scope.matchingElements) {
          scope.navigateBetweenMatchingElements('+')
        }
      })

    }
  }
})<commit_msg>Add keyboard shortcut for toggle search bar<commit_after>'use strict'

angular.module('serinaApp').directive('toolbar', function ($timeout, $rootScope) {
  return {
    restrict: 'E',
    templateUrl: 'views/commons/toolbar.html',
    link: function (scope) {

      scope.searchOpen = false;
      scope.search = null

      var clearMatchingElements = function () {
        scope.matchingElements = []
      }

      scope.initiateSearch = function () {
        scope.search = ''
        $timeout(function () {
          document.getElementById('search-input').focus()
        }, 10)
        clearMatchingElements()
        scope.searchOpen = true;
      }

      scope.showPreSearchBar = function () {
        return scope.search === null
      }

      scope.endSearch = function () {
        scope.search = null
        clearMatchingElements()
        scope.currentMatchingElement = 0
        scope.searchOpen = false;
      }

      scope.searchKey = function () {
        if (scope.search !== '') {
          var inputKeys = document.querySelectorAll('translation md-card .key')
          scope.matchingElements = []
          scope.currentMatchingElement = 0
          for (var iterator = 0; iterator < inputKeys.length; iterator++) {
            if (inputKeys[iterator].value.toLowerCase().indexOf(scope.search.toLowerCase()) !== -1) {
              scope.matchingElements.push(inputKeys[iterator])
            }
          }

          if (scope.matchingElements.length === 0) {
            scope.endSearch()
          } else {
            scope.matchingElements[0].focus()
          }
        }
      }

      scope.navigateBetweenMatchingElements = function (sign) {
        if (sign === '-' || sign === '+') {
          if (sign === '-') {
            scope.currentMatchingElement--
            if (scope.currentMatchingElement < 0) {
              scope.currentMatchingElement = scope.matchingElements.length - 1
            }
          } else if (sign === '+') {
            scope.currentMatchingElement++
            if (scope.currentMatchingElement > scope.matchingElements.length - 1) {
              scope.currentMatchingElement = 0
            }
          }
          scope.matchingElements[scope.currentMatchingElement].focus()
        }
      }

      Mousetrap.bindGlobal('ctrl+f', function () {
        if ($rootScope.breadcrumb[0].href !== '/hub' && $rootScope.breadcrumb[0].href !== '/settings') {
          if (scope.searchOpen) {
            scope.endSearch();
          } else {
            scope.initiateSearch();
          }
        }
      })

      Mousetrap.bindGlobal('ctrl+up', function () {
        if (scope.matchingElements) {
          scope.navigateBetweenMatchingElements('-')
        }
      })

      Mousetrap.bindGlobal('ctrl+down', function () {
        if (scope.matchingElements) {
          scope.navigateBetweenMatchingElements('+')
        }
      })

    }
  }
})
{'fraction_non_alphanumeric': 0.1280431146627021, 'fraction_numerical': 0.004831815647649135, 'mean_word_length': 1.9139144558743908, 'pattern_counts': {'":': 0, '<': 7, '<?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': '660799', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1410, 'n_words': 231}