<commit_before>module ProMotion
  class TabBarController < UITabBarController
    attr_accessor :pm_tab_delegate, :name

    def self.new(*screens)
      tab_bar_controller = alloc.init

      screens = screens.flatten.map { |s| s.respond_to?(:new) ? s.new : s } # Initialize any classes

      tag_index = 0
      view_controllers = screens.map do |s|
        s.tabBarItem.tag = tag_index
        s.tab_bar = WeakRef.new(tab_bar_controller) if s.respond_to?("tab_bar=")
        tag_index += 1
        s.navigationController || s
      end

      tab_bar_controller.viewControllers = view_controllers
      name = ""
      tab_bar_controller.delegate = tab_bar_controller
      tab_bar_controller
    end

    def name=(n)
      @name = n
      tab_bar_order = NSUserDefaults.standardUserDefaults.arrayForKey("tab_bar_order_#{@name}")
      if tab_bar_order
        sorted_controllers = []
        unsorted_controllers = self.viewControllers.copy
        tab_bar_order.each do |order|
          sorted_controllers << unsorted_controllers[order]
        end
        self.viewControllers = sorted_controllers
      end
    end

    def open_tab(tab)
      if tab.is_a? String
        selected_tab_vc = find_tab(tab)
      elsif tab.is_a? Numeric
        selected_tab_vc = viewControllers[tab]
      end

      if selected_tab_vc
        self.selectedViewController = selected_tab_vc
        on_tab_selected_try(selected_tab_vc)

        selected_tab_vc
      else
        PM.logger.error "Unable to open tab #{tab.to_s} -- not found."
        nil<commit_msg>Make sure we always open the tab to the far left<commit_after>module ProMotion
  class TabBarController < UITabBarController
    attr_accessor :pm_tab_delegate, :name

    def self.new(*screens)
      tab_bar_controller = alloc.init

      screens = screens.flatten.map { |s| s.respond_to?(:new) ? s.new : s } # Initialize any classes

      tag_index = 0
      view_controllers = screens.map do |s|
        s.tabBarItem.tag = tag_index
        s.tab_bar = WeakRef.new(tab_bar_controller) if s.respond_to?("tab_bar=")
        tag_index += 1
        s.navigationController || s
      end

      tab_bar_controller.viewControllers = view_controllers
      name = ""
      tab_bar_controller.delegate = tab_bar_controller
      tab_bar_controller
    end

    def name=(n)
      @name = n
      tab_bar_order = NSUserDefaults.standardUserDefaults.arrayForKey("tab_bar_order_#{@name}")
      if tab_bar_order
        sorted_controllers = []
        unsorted_controllers = self.viewControllers.copy
        tab_bar_order.each do |order|
          sorted_controllers << unsorted_controllers[order]
        end
        self.viewControllers = sorted_controllers
        open_tab(0) # Open the tab on the far left
      end
    end

    def open_tab(tab)
      if tab.is_a? String
        selected_tab_vc = find_tab(tab)
      elsif tab.is_a? Numeric
        selected_tab_vc = viewControllers[tab]
      end

      if selected_tab_vc
        self.selectedViewController = selected_tab_vc
        on_tab_selected_try(selected_tab_vc)

        selected_tab_vc
      else
        PM.logger.error "Unable to open tab #{tab.to_s} -- not found."
        nil
{'fraction_non_alphanumeric': 0.07535959974984366, 'fraction_numerical': 0.0015634771732332708, 'mean_word_length': 2.5782997762863533, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '2393654', 'n_tokens_mistral': 1021, 'n_tokens_neox': 1002, 'n_words': 207}