<commit_before>﻿using System;
using System.Linq;
using Silphid.Extensions;
using Silphid.Requests;
using Silphid.Showzup.Navigation;
using Silphid.Showzup.Requests;
using UniRx;
using UnityEngine;
using UnityEngine.EventSystems;

namespace Silphid.Showzup
{
    public class SelectionControl : ListControl, IMoveHandler, IRequestHandler
    {      
        private readonly ReactiveProperty<IView> _selectedView = new ReactiveProperty<IView>();

        public IReadOnlyReactiveProperty<IView> SelectedView => _selectedView;
        public ReactiveProperty<int?> SelectedIndex { get; } = new ReactiveProperty<int?>();

        public bool WrapAround;
        public int RowsOrColumns = 1;
        public bool AutoSelectFirst = true;
        public bool HandlesSelectRequest;

        public override GameObject ForwardSelection() => _selectedView.Value?.GameObject;

        protected override void Start()
        {
            if (Orientation == NavigationOrientation.None)
                throw new InvalidOperationException(
                    $"SelectionControl is missing orientation value on gameObject {gameObject.ToHierarchyPath()}");

            Views
                .CombineLatest(SelectedIndex, (views, selectedIndex) => new {views, selectedIndex})
                .Subscribe(x =>
                {
                    _selectedView.Value = x.views.GetAtOrDefault(x.selectedIndex);

                    if (IsSelfOrDescendantSelected.Value)
                        _selectedView.Value?.Select();
                })
                .AddTo(this);

            SubscribeToUpdateFocusables(SelectedView);
        }

        protected override void RemoveAllViews(GameObject container, GameObject except = null)
        {<commit_msg>Fixed AutoSelectFirst<commit_after>﻿using System;
using System.Linq;
using JetBrains.Annotations;
using Silphid.Extensions;
using Silphid.Requests;
using Silphid.Showzup.Navigation;
using Silphid.Showzup.Requests;
using UniRx;
using UnityEngine;
using UnityEngine.EventSystems;

namespace Silphid.Showzup
{
    public class SelectionControl : ListControl, IMoveHandler, IRequestHandler
    {
        private readonly ReactiveProperty<IView> _selectedView = new ReactiveProperty<IView>();

        public IReadOnlyReactiveProperty<IView> SelectedView => _selectedView;
        public ReactiveProperty<int?> SelectedIndex { get; } = new ReactiveProperty<int?>();

        public bool WrapAround;
        public int RowsOrColumns = 1;
        public bool AutoSelectFirst = true;
        public bool HandlesSelectRequest;

        public override GameObject ForwardSelection() => _selectedView.Value?.GameObject;

        protected override void Start()
        {
            if (Orientation == NavigationOrientation.None)
                throw new InvalidOperationException(
                    $"SelectionControl is missing orientation value on gameObject {gameObject.ToHierarchyPath()}");

            Views
                .CombineLatest(SelectedIndex, (views, selectedIndex) => new {views, selectedIndex})
                .Subscribe(x =>
                {
                    _selectedView.Value = x.views.GetAtOrDefault(x.selectedIndex);

                    if (IsSelfOrDescendantSelected.Value)
                        _selectedView.Value?.Select();
                })
                .AddTo(this);

            SubscribeToUpdateFocusables(SelectedView);
        }

        [Pure]
        protected override IObservable<IView> PresentView(object input, Options options = null) =>
            base.PresentView(input, options)
                .DoOnCompleted(() =>
                {
                    if (AutoSelectFirst)
                        SelectFirst();
                });

        protected override void RemoveAllViews(GameObject container, GameObject except = null)
        {
{'fraction_non_alphanumeric': 0.07854906054279749, 'fraction_numerical': 0.0005219206680584551, 'mean_word_length': 2.428443649373882, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 24, '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': '979023', 'n_tokens_mistral': 973, 'n_tokens_neox': 920, 'n_words': 222}