<commit_before>View = require './view'

Requests = require '../collections/Requests'

class GlobalSearchView extends View

    lastSearchQuery: ''
    lastResponse: []

    template: require '../templates/globalSearch'

    events: ->
        _.extend super,
            'click [data-action="close-global-seach"]': 'hide'

    initialize: ->
        @requests = new Requests [], {'all'}

        $(window).on 'keydown', (event) =>
            focusBody = $(event.target).is 'body'
            focusInput = $(event.target).is @$ 'input[type="search"]'

            modifierKey = event.metaKey or event.shiftKey
            sPressed = event.keyCode in [83, 84] and not modifierKey
            escPressed = event.keyCode is 27

            if escPressed and (focusBody or focusInput)
                @hide()
            else if sPressed and focusBody
                @show()
                event.preventDefault()

    render: ->
        @$el.html @template()

        @setUpTypeahead()

    setUpTypeahead: ->
        sourceFunction = (query, process) =>
            # Ignore empty queries<commit_msg>ctrl-t, which on a non-Mac system should open a new tab, now doesn't get captured causing global search to open<commit_after>View = require './view'

Requests = require '../collections/Requests'

class GlobalSearchView extends View

    lastSearchQuery: ''
    lastResponse: []

    template: require '../templates/globalSearch'

    events: ->
        _.extend super,
            'click [data-action="close-global-seach"]': 'hide'

    initialize: ->
        @requests = new Requests [], {'all'}

        $(window).on 'keydown', (event) =>
            focusBody = $(event.target).is 'body'
            focusInput = $(event.target).is @$ 'input[type="search"]'

            modifierKey = event.metaKey or event.shiftKey or event.ctrlKey
            sPressed = event.keyCode in [83, 84] and not modifierKey
            escPressed = event.keyCode is 27

            if escPressed and (focusBody or focusInput)
                @hide()
            else if sPressed and focusBody
                @show()
                event.preventDefault()

    render: ->
        @$el.html @template()

        @setUpTypeahead()

    setUpTypeahead: ->
        sourceFunction = (query, process) =>
            # Ignore empty queries
{'fraction_non_alphanumeric': 0.11932555123216602, 'fraction_numerical': 0.005188067444876783, 'mean_word_length': 2.0407358738501973, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4543968', 'n_tokens_mistral': 655, 'n_tokens_neox': 617, 'n_words': 172}