<commit_before>﻿using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// Main logic for the dev spawner menu
/// </summary>
public class GUI_DevSpawner : MonoBehaviour
{

	[Tooltip("Prefab that should be used for each list item")]
	public GameObject listItemPrefab;
	[Tooltip("content panel into which the list items should be placed")]
	public GameObject contentPanel;
	public InputField searchBox;

	[Tooltip("Always perform a wildcard search, with wildcard being added at the end")]
	public bool alwaysWildcard = true;
	[Tooltip("Update search results as you type into the search box.")]
	public bool searchWhileTyping = false;
	[Tooltip("If searchWhileTyping is turned on, don't start searching until at least this many" +
	         " characters are entered.")]
	public int minCharactersForSearch = 3;

	// search index
	private SpawnerSearch spawnerSearch;

	private bool isFocused;

	void Start()
    {
	    spawnerSearch = SpawnerSearch.ForPrefabs(Spawn.SpawnablePrefabs());
    }

    /// <summary>
    /// There is no event for focusing input, so we must check for it manually in Update
    /// </summary>
    void Update()
    {
	    if (searchBox.isFocused && isFocused == false)
	    {
		    InputFocus();
	    }
	    else if (searchBox.isFocused == false && isFocused)
	    {
		    InputUnfocus();
	    }
    }

    private void InputFocus()
    {
	    //disable keyboard commands while input is focused
	    isFocused = true;
	    UIManager.IsInputFocus = true;
    }

    private void InputUnfocus()
    {
	    //disable keyboard commands while input is focused
	    isFocused = false;
	    UIManager.IsInputFocus = false;
    }

    public void OnSearchBoxChanged()
    {
	    if (searchWhileTyping)
	    {
		    if (searchBox.text.Length >= minCharactersForSearch)
		    {
			    Search();
		    }
	    }
    }

    public void Search()
    {
	    //delete previous results
	    foreach (Transform child in contentPanel.transform)
	    {
		    Destroy(child.gameObject);
	    }

	    var docs = spawnerSearch.Search(searchBox.text);

	    //display new results
	    foreach (var doc in docs)
	    {
		    CreateListItem(doc);
	    }
    }

    //add a list item to the content panel for spawning the specified result
    private void CreateListItem(DevSpawnerDocument doc)
    {
	    GameObject listItem = Instantiate(listItemPrefab);
	    listItem.GetComponent<DevSpawnerListItemController>().Initialize(doc);<commit_msg>Fixes the dev spawner searching with an empty or really short string. (#6263)<commit_after>﻿using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// Main logic for the dev spawner menu
/// </summary>
public class GUI_DevSpawner : MonoBehaviour
{

	[Tooltip("Prefab that should be used for each list item")]
	public GameObject listItemPrefab;
	[Tooltip("content panel into which the list items should be placed")]
	public GameObject contentPanel;
	public InputField searchBox;

	[Tooltip("Always perform a wildcard search, with wildcard being added at the end")]
	public bool alwaysWildcard = true;
	[Tooltip("Update search results as you type into the search box.")]
	public bool searchWhileTyping = false;
	[Tooltip("If searchWhileTyping is turned on, don't start searching until at least this many" +
	         " characters are entered.")]
	public int minCharactersForSearch = 3;

	// search index
	private SpawnerSearch spawnerSearch;

	private bool isFocused;

	void Start()
    {
	    spawnerSearch = SpawnerSearch.ForPrefabs(Spawn.SpawnablePrefabs());
    }

    /// <summary>
    /// There is no event for focusing input, so we must check for it manually in Update
    /// </summary>
    void Update()
    {
	    if (searchBox.isFocused && isFocused == false)
	    {
		    InputFocus();
	    }
	    else if (searchBox.isFocused == false && isFocused)
	    {
		    InputUnfocus();
	    }
    }

    private void InputFocus()
    {
	    //disable keyboard commands while input is focused
	    isFocused = true;
	    UIManager.IsInputFocus = true;
    }

    private void InputUnfocus()
    {
	    //disable keyboard commands while input is focused
	    isFocused = false;
	    UIManager.IsInputFocus = false;
    }

    public void OnSearchBoxChanged()
    {
	    if (searchWhileTyping)
	    {
		    Search();
	    }
    }

    public void Search()
    {
	    if (searchBox.text.Length < minCharactersForSearch)
	    {
		    return;
	    }
		//delete previous results
	    foreach (Transform child in contentPanel.transform)
	    {
		    Destroy(child.gameObject);
	    }

	    var docs = spawnerSearch.Search(searchBox.text);

	    //display new results
	    foreach (var doc in docs)
	    {
		    CreateListItem(doc);
	    }
    }

    //add a list item to the content panel for spawning the specified result
    private void CreateListItem(DevSpawnerDocument doc)
    {
	    GameObject listItem = Instantiate(listItemPrefab);
	    listItem.GetComponent<DevSpawnerListItemController>().Initialize(doc);
{'fraction_non_alphanumeric': 0.08881711748082358, 'fraction_numerical': 0.0012111425111021397, 'mean_word_length': 2.8650546021840873, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '984870', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1409, 'n_words': 452}