<commit_before>window.feedbin ?= {}

jQuery ->
  new feedbin.Keyboard()  

class feedbin.Keyboard
  constructor: ->
    @columns =
      feeds: $('.feeds')
      entries: $('.entries')

    @selectColumn('feeds')
    
    # The right key should be locked until entries finishes loading
    @rightLock = false
    @waitingForEntries = false
    
    @bindKeys()
    @bindEvents()
    
  bindEvents: ->
    $(document).on 'click', '[data-behavior~=open_item]',  (event) =>
      parent = $(event.currentTarget).parents('div')
      if parent.hasClass('entries')
        @selectColumn('entries')
      else if parent.hasClass('feeds')
        @selectColumn('feeds')
    
    $(document).on 'ajax:complete', '[data-behavior~=show_entries]', =>
      @rightLock = false
      if @waitingForEntries
        @openFirstItem()
        @waitingForEntries = false

  bindKeys: ->
    Mousetrap.bind ['up', 'down', 'left', 'right', 'j', 'k', 'h', 'l'], (event, combo) =>
      
      # If share menu is showing intercept up down
      dropdown = $('.dropdown-wrap')
      if feedbin.shareOpen()
        nextShare = false
        selectedShare = $('li.selected', dropdown)
        if 'down' == combo
          nextShare = selectedShare.next()
          if nextShare.length == 0
            nextShare = $('li:first-child', dropdown)
        else if 'up' == combo
          nextShare = selectedShare.prev()
          if nextShare.length == 0
            nextShare = $('li:last-child', dropdown)
        
        if nextShare
          $('li.selected', dropdown).removeClass('selected')
          nextShare.addClass('selected')

        event.preventDefault()
        return false

      @setEnvironment()
      
      if 'down' == combo || 'j' == combo
        if 'entry-content' == @selectedColumnName()
          @scrollContent(30, 'down')
        else
          @item = @next
          @selectItem()
      else if 'up' == combo || 'k' == combo
        if 'entry-content' == @selectedColumnName()
          @scrollContent(30, 'up')
        else
          @item = @previous
          @selectItem()
      else if 'right' == combo || 'l' == combo
        if 'feeds' == @selectedColumnName()
          if @rightLock
            @waitingForEntries = true
          else
            @openFirstItem()
        else if 'entries' == @selectedColumnName()
          @selectColumn('entry-content')
          
      else if 'left' == combo || 'h' == combo
        if 'entry-content' == @selectedColumnName()
          @selectColumn('entries')
        else if 'entries' == @selectedColumnName()
          if @columns['feeds'].find('.selected').length > 0
            @selectColumn('feeds')
          else
            $("[data-feed-id=#{feedbin.feedCandidates[0]}]").find('[data-behavior~=open_item]').click()
            feedbin.feedCandidates = []
      event.preventDefault()

    Mousetrap.bind ['space'], (event, combo) =>
      @setEnvironment()
      if @hasEntryContent()
        @selectColumn('entry-content')
        interval = $('.entry-content').height() - 20
        @scrollContent(interval, 'down')
      else if @hasUnreadEntries()
        @selectNextUnreadEntry()
      else if @hasUnreadFeeds()
        @selectNextUnreadFeed()
      event.preventDefault()

    # Star
    Mousetrap.bind 's', (event, combo) =>
      $('[data-behavior~=toggle_starred]').submit()
      event.preventDefault()

    # Read/Unread
    Mousetrap.bind 'm', (event, combo) =>
      $('[data-behavior~=toggle_read]').submit()
      event.preventDefault()

    # Content View
    Mousetrap.bind 'c', (event, combo) =>
      $('[data-behavior~=toggle_content_view]').submit()
      event.preventDefault()

    # Go to all
    Mousetrap.bind 'g a', (event, combo) =>
      $('[data-behavior~=all_unread] [data-behavior~=open_item]').click()
      event.preventDefault()
      
    # Go to starred
    Mousetrap.bind 'g s', (event, combo) =>
      $('[data-behavior~=starred] [data-behavior~=open_item]').click()
      event.preventDefault()
      
    # Mark as read
    Mousetrap.bind 'shift+a', (event, combo) =>
      currentEntry = @columns['entries'].find('.selected')
      @alternateEntryCandidates = []
      @alternateEntryCandidates.push currentEntry.next() if currentEntry.next().length
      @alternateEntryCandidates.push currentEntry.prev() if currentEntry.prev().length
        
      $('[data-behavior~=mark_all_as_read]').find('[type=submit]').click()
      event.preventDefault()
      
    # Add subscription
    Mousetrap.bind 'a', (event, combo) =>
      $('[name="subscription[feeds][feed_url]"]').focus()
      event.preventDefault()

    # Show Keyboard shortcuts
    Mousetrap.bind '?', (event, combo) =>
      if feedbin.modalShowing == true
        $('.modal').modal('hide')
        feedbin.modalShowing = false
      else
        content = $('[data-behavior~=keyboard_shortcuts]').html()
        feedbin.modalBox(content);
      event.preventDefault()

    # Open original article
    Mousetrap.bind 'v', (event, combo) =>
      content = $('.entry-header').find('a')[0].click()
      event.preventDefault()

    # Open original article
    Mousetrap.bind 'V', (event, combo) =>
      href = $('.entry-header').find('a').attr('href')
      if href
        feedbin.openLinkInBackground(href)<commit_msg>Only submit the first instance of mark all as read.<commit_after>window.feedbin ?= {}

jQuery ->
  new feedbin.Keyboard()  

class feedbin.Keyboard
  constructor: ->
    @columns =
      feeds: $('.feeds')
      entries: $('.entries')

    @selectColumn('feeds')
    
    # The right key should be locked until entries finishes loading
    @rightLock = false
    @waitingForEntries = false
    
    @bindKeys()
    @bindEvents()
    
  bindEvents: ->
    $(document).on 'click', '[data-behavior~=open_item]',  (event) =>
      parent = $(event.currentTarget).parents('div')
      if parent.hasClass('entries')
        @selectColumn('entries')
      else if parent.hasClass('feeds')
        @selectColumn('feeds')
    
    $(document).on 'ajax:complete', '[data-behavior~=show_entries]', =>
      @rightLock = false
      if @waitingForEntries
        @openFirstItem()
        @waitingForEntries = false

  bindKeys: ->
    Mousetrap.bind ['up', 'down', 'left', 'right', 'j', 'k', 'h', 'l'], (event, combo) =>
      
      # If share menu is showing intercept up down
      dropdown = $('.dropdown-wrap')
      if feedbin.shareOpen()
        nextShare = false
        selectedShare = $('li.selected', dropdown)
        if 'down' == combo
          nextShare = selectedShare.next()
          if nextShare.length == 0
            nextShare = $('li:first-child', dropdown)
        else if 'up' == combo
          nextShare = selectedShare.prev()
          if nextShare.length == 0
            nextShare = $('li:last-child', dropdown)
        
        if nextShare
          $('li.selected', dropdown).removeClass('selected')
          nextShare.addClass('selected')

        event.preventDefault()
        return false

      @setEnvironment()
      
      if 'down' == combo || 'j' == combo
        if 'entry-content' == @selectedColumnName()
          @scrollContent(30, 'down')
        else
          @item = @next
          @selectItem()
      else if 'up' == combo || 'k' == combo
        if 'entry-content' == @selectedColumnName()
          @scrollContent(30, 'up')
        else
          @item = @previous
          @selectItem()
      else if 'right' == combo || 'l' == combo
        if 'feeds' == @selectedColumnName()
          if @rightLock
            @waitingForEntries = true
          else
            @openFirstItem()
        else if 'entries' == @selectedColumnName()
          @selectColumn('entry-content')
          
      else if 'left' == combo || 'h' == combo
        if 'entry-content' == @selectedColumnName()
          @selectColumn('entries')
        else if 'entries' == @selectedColumnName()
          if @columns['feeds'].find('.selected').length > 0
            @selectColumn('feeds')
          else
            $("[data-feed-id=#{feedbin.feedCandidates[0]}]").find('[data-behavior~=open_item]').click()
            feedbin.feedCandidates = []
      event.preventDefault()

    Mousetrap.bind ['space'], (event, combo) =>
      @setEnvironment()
      if @hasEntryContent()
        @selectColumn('entry-content')
        interval = $('.entry-content').height() - 20
        @scrollContent(interval, 'down')
      else if @hasUnreadEntries()
        @selectNextUnreadEntry()
      else if @hasUnreadFeeds()
        @selectNextUnreadFeed()
      event.preventDefault()

    # Star
    Mousetrap.bind 's', (event, combo) =>
      $('[data-behavior~=toggle_starred]').submit()
      event.preventDefault()

    # Read/Unread
    Mousetrap.bind 'm', (event, combo) =>
      $('[data-behavior~=toggle_read]').submit()
      event.preventDefault()

    # Content View
    Mousetrap.bind 'c', (event, combo) =>
      $('[data-behavior~=toggle_content_view]').submit()
      event.preventDefault()

    # Go to all
    Mousetrap.bind 'g a', (event, combo) =>
      $('[data-behavior~=all_unread] [data-behavior~=open_item]').click()
      event.preventDefault()
      
    # Go to starred
    Mousetrap.bind 'g s', (event, combo) =>
      $('[data-behavior~=starred] [data-behavior~=open_item]').click()
      event.preventDefault()
      
    # Mark as read
    Mousetrap.bind 'shift+a', (event, combo) =>
      currentEntry = @columns['entries'].find('.selected')
      @alternateEntryCandidates = []
      @alternateEntryCandidates.push currentEntry.next() if currentEntry.next().length
      @alternateEntryCandidates.push currentEntry.prev() if currentEntry.prev().length
        
      $('[data-behavior~=mark_all_as_read]').first().find('[type=submit]').click()
      event.preventDefault()
      
    # Add subscription
    Mousetrap.bind 'a', (event, combo) =>
      $('[name="subscription[feeds][feed_url]"]').focus()
      event.preventDefault()

    # Show Keyboard shortcuts
    Mousetrap.bind '?', (event, combo) =>
      if feedbin.modalShowing == true
        $('.modal').modal('hide')
        feedbin.modalShowing = false
      else
        content = $('[data-behavior~=keyboard_shortcuts]').html()
        feedbin.modalBox(content);
      event.preventDefault()

    # Open original article
    Mousetrap.bind 'v', (event, combo) =>
      content = $('.entry-header').find('a')[0].click()
      event.preventDefault()

    # Open original article
    Mousetrap.bind 'V', (event, combo) =>
      href = $('.entry-header').find('a').attr('href')
      if href
        feedbin.openLinkInBackground(href)
{'fraction_non_alphanumeric': 0.1569439217162213, 'fraction_numerical': 0.0020700037636432068, 'mean_word_length': 2.4780759162303663, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, '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': '3004303', 'n_tokens_mistral': 3260, 'n_tokens_neox': 3112, 'n_words': 644}