<commit_before>﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Linq;

namespace uREPL
{

public class CompletionView : MonoBehaviour
{
	private const string contentGameObjectName = "Content";
	private const float scrollDamping = 0.3f;

	public GameObject itemPrefab;
	public Vector3 offset = new Vector3(0, 10, 0);
	private Transform content;
	private ScrollRect scroll;
	private RectTransform rect;

	private int currentIndex_ = 0;
	private float scrollPos_ = 0;

	public int itemCount
	{
		get { return content.childCount; }
	}

	private int itemIndex
	{
		get { return itemCount - 1 - currentIndex_; }
	}

	public Vector3 position
	{
		get { return rect.localPosition; }
		set { rect.localPosition = value + offset; }
	}

	public string selectedCode
	{
		get {
			return itemCount > 0 ?
				content.GetChild(itemIndex).GetComponent<CompletionItem>().code : "";
		}
	}

	void Awake()
	{
		rect    = GetComponent<RectTransform>();
		scroll  = GetComponent<ScrollRect>();
		content = transform.FindChild(contentGameObjectName);
	}

	void Update()
	{
		for (int i = 0; i < itemCount; ++i) {
			content.GetChild(i).GetComponent<CompletionItem>().SetHighlight(i == itemIndex);
		}
	}

	void LateUpdate()
	{
		var targetScrollPos = (itemCount <= 1) ? 0f : 1f * currentIndex_ / (itemCount - 1);
		scrollPos_ += (targetScrollPos - scrollPos_) * scrollDamping;
		scroll.verticalNormalizedPosition = scrollPos_;
	}

	public void SetCompletions(CompletionInfo[] completions)
	{
		Reset();
		if (completions.Length == 0) return;
		foreach (var info in completions.Reverse()) {
			var itemObject = Instantiate(itemPrefab) as GameObject;
			itemObject.transform.SetParent(content);
			var item = itemObject.GetComponent<CompletionItem>();
			item.SetCode(info.code, info.prefix);
			item.type = info.type;
		}
		LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
	}

	private void Clear()
	{
		for (int i = 0; i < itemCount; ++i) {
			var item = content.GetChild(i).gameObject;
			Destroy(item);
		}
	}

	public void Next()
	{
		if (itemCount == 0) {
			currentIndex_ = 0;<commit_msg>wrap >5.2 api with if directive.<commit_after>﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Linq;

namespace uREPL
{

public class CompletionView : MonoBehaviour
{
	private const string contentGameObjectName = "Content";
	private const float scrollDamping = 0.3f;

	public GameObject itemPrefab;
	public Vector3 offset = new Vector3(0, 10, 0);
	private Transform content;
	private ScrollRect scroll;
	private RectTransform rect;

	private int currentIndex_ = 0;
	private float scrollPos_ = 0;

	public int itemCount
	{
		get { return content.childCount; }
	}

	private int itemIndex
	{
		get { return itemCount - 1 - currentIndex_; }
	}

	public Vector3 position
	{
		get { return rect.localPosition; }
		set { rect.localPosition = value + offset; }
	}

	public string selectedCode
	{
		get {
			return itemCount > 0 ?
				content.GetChild(itemIndex).GetComponent<CompletionItem>().code : "";
		}
	}

	void Awake()
	{
		rect    = GetComponent<RectTransform>();
		scroll  = GetComponent<ScrollRect>();
		content = transform.FindChild(contentGameObjectName);
	}

	void Update()
	{
		for (int i = 0; i < itemCount; ++i) {
			content.GetChild(i).GetComponent<CompletionItem>().SetHighlight(i == itemIndex);
		}
	}

	void LateUpdate()
	{
		var targetScrollPos = (itemCount <= 1) ? 0f : 1f * currentIndex_ / (itemCount - 1);
		scrollPos_ += (targetScrollPos - scrollPos_) * scrollDamping;
		scroll.verticalNormalizedPosition = scrollPos_;
	}

	public void SetCompletions(CompletionInfo[] completions)
	{
		Reset();
		if (completions.Length == 0) return;
		foreach (var info in completions.Reverse()) {
			var itemObject = Instantiate(itemPrefab) as GameObject;
			itemObject.transform.SetParent(content);
			var item = itemObject.GetComponent<CompletionItem>();
			item.SetCode(info.code, info.prefix);
			item.type = info.type;
		}
#if UNITY_5_2 || UNITY_5_3
		LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
#endif
	}

	private void Clear()
	{
		for (int i = 0; i < itemCount; ++i) {
			var item = content.GetChild(i).gameObject;
			Destroy(item);
		}
	}

	public void Next()
	{
		if (itemCount == 0) {
			currentIndex_ = 0;
{'fraction_non_alphanumeric': 0.11523301646185949, 'fraction_numerical': 0.011592858798979828, 'mean_word_length': 4.141835518474374, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 18, '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': '5892350', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1384, 'n_words': 346}