<commit_before>define [
  'underscore'
  'i18n!react_files'
  'react'
  '../mixins/BackboneMixin'
  'compiled/models/Folder'
  'compiled/fn/preventDefault'
  '../modules/FocusStore'
  'classnames'
  'compiled/jquery.rails_flash_notifications'
], (_, I18n, React, BackboneMixin, Folder, preventDefault, FocusStore, classnames) ->

  FolderChild =
    displayName: 'FolderChild'

    mixins: [BackboneMixin('model')]

    getInitialState: ->
      editing: @props.model.isNew()
      hideKeyboardCheck: true
      isSelected: @props.isSelected

    componentDidMount: ->
      @focusNameInput() if @state.editing

    startEditingName: ->
      @setState editing: true, @focusNameInput

    focusPreviousElement: ->
      @previouslyFocusedElement?.focus()
      return if document.activeElement ==  @previouslyFocusedElement
      @focusNameLink()

    focusNameInput: ->

      # If the activeElement is currently the "body" that means they clicked on some type of cog to enable this state.
      # This is an edge case that ensures focus remains in context of whats being edited, in this case, the nameLink
      @previouslyFocusedElement = if document.activeElement.nodeName == "BODY"
                                    @refs.nameLink?.getDOMNode()
                                  else
                                    document.activeElement

      setTimeout () =>
        @refs.newName?.getDOMNode().focus()
      , 0

    focusNameLink: ->
      setTimeout () =>
        @refs.nameLink?.getDOMNode().focus()
      , 0

    saveNameEdit: -><commit_msg>fix keyboard focus issue when creating new folder<commit_after>define [
  'underscore'
  'i18n!react_files'
  'react'
  '../mixins/BackboneMixin'
  'compiled/models/Folder'
  'compiled/fn/preventDefault'
  '../modules/FocusStore'
  'classnames'
  'compiled/jquery.rails_flash_notifications'
], (_, I18n, React, BackboneMixin, Folder, preventDefault, FocusStore, classnames) ->

  FolderChild =
    displayName: 'FolderChild'

    mixins: [BackboneMixin('model')]

    getInitialState: ->
      editing: @props.model.isNew()
      hideKeyboardCheck: true
      isSelected: @props.isSelected

    componentDidMount: ->
      @focusNameInput() if @state.editing

    startEditingName: ->
      @setState editing: true, @focusNameInput

    focusPreviousElement: ->
      @previouslyFocusedElement?.focus()
      return if document.activeElement ==  @previouslyFocusedElement
      @focusNameLink()

    focusNameInput: ->

      # If the activeElement is currently the "body" that means they clicked on some type of cog to enable this state.
      # This is an edge case that ensures focus remains in context of whats being edited, in this case, the nameLink
      @previouslyFocusedElement = if document.activeElement.nodeName == "BODY"
                                    @refs.nameLink?.getDOMNode()
                                  else
                                    document.activeElement

      setTimeout () =>
        @refs.newName?.getDOMNode().focus()
      , 0

    focusNameLink: ->
      setTimeout () =>
        React.findDOMNode(@refs.nameLink)?.focus()
      , 0

    saveNameEdit: ->
{'fraction_non_alphanumeric': 0.10296904611497157, 'fraction_numerical': 0.003790271636133923, 'mean_word_length': 2.5425055928411635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3433430', 'n_tokens_mistral': 926, 'n_tokens_neox': 884, 'n_words': 209}