<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')
      return

    $(document).on 'ajax:complete', '[data-behavior~=show_entries]', =>
      @rightLock = false
      if @waitingForEntries
        @openFirstItem()
        @waitingForEntries = false
      return

    $(document).on 'click', '.entry-content', =>
      @selectColumn('entry-content')
      return

  navigateShareMenu: (combo) ->
    # If share menu is showing intercept up down
    dropdown = $('[data-behavior~=toggle_share_menu]').parents('.dropdown-wrap')
    if dropdown.hasClass('open')
      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')

  navigateFeedbin: (combo) ->
    @setEnvironment()
    if 'pageup' == combo
      if 'entry-content' == @selectedColumnName() || feedbin.isFullScreen()
        @scrollContent(@contentHeight() - 100, 'down')
    else if 'pagedown' == combo
      if 'entry-content' == @selectedColumnName() || feedbin.isFullScreen()
        @scrollContent(@contentHeight() - 100, 'up')
    else if 'down' == combo || 'j' == combo
      if 'entry-content' == @selectedColumnName() || feedbin.isFullScreen()
        @scrollContent(30, 'down')
      else
        @item = @next
        @selectItem()
    else if 'up' == combo || 'k' == combo
      if 'entry-content' == @selectedColumnName() || feedbin.isFullScreen()
        @scrollContent(30, 'up')
      else
        @item = @previous
        @selectItem()
    else if 'right' == combo || 'l' == combo
      if 'feeds' == @selectedColumnName()
        if @rightLock<commit_msg>Oops! Had mixed up pageup and pagedown. Now fixed<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')
      return

    $(document).on 'ajax:complete', '[data-behavior~=show_entries]', =>
      @rightLock = false
      if @waitingForEntries
        @openFirstItem()
        @waitingForEntries = false
      return

    $(document).on 'click', '.entry-content', =>
      @selectColumn('entry-content')
      return

  navigateShareMenu: (combo) ->
    # If share menu is showing intercept up down
    dropdown = $('[data-behavior~=toggle_share_menu]').parents('.dropdown-wrap')
    if dropdown.hasClass('open')
      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')

  navigateFeedbin: (combo) ->
    @setEnvironment()
    if 'pagedown' == combo
      if 'entry-content' == @selectedColumnName() || feedbin.isFullScreen()
        @scrollContent(@contentHeight() - 100, 'down')
    else if 'pageup' == combo
      if 'entry-content' == @selectedColumnName() || feedbin.isFullScreen()
        @scrollContent(@contentHeight() - 100, 'up')
    else if 'down' == combo || 'j' == combo
      if 'entry-content' == @selectedColumnName() || feedbin.isFullScreen()
        @scrollContent(30, 'down')
      else
        @item = @next
        @selectItem()
    else if 'up' == combo || 'k' == combo
      if 'entry-content' == @selectedColumnName() || feedbin.isFullScreen()
        @scrollContent(30, 'up')
      else
        @item = @previous
        @selectItem()
    else if 'right' == combo || 'l' == combo
      if 'feeds' == @selectedColumnName()
        if @rightLock
{'fraction_non_alphanumeric': 0.15232558139534882, 'fraction_numerical': 0.004651162790697674, 'mean_word_length': 2.761661807580175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '5988801', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1498, 'n_words': 355}