Example #1
0
    public void OnKeyDown()
    {
        if (!Input.anyKeyDown)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Mouse0))
        {
            _modeSelector.EnterNormalMode();
            return;
        }

        if (Input.GetKeyDown(KeyCode.Return))
        {
            var selectedAction = _fuzzyFinder.current;
            if (selectedAction != null)
            {
                if (selectedAction.StartsWith(_selectByNameCommandNamespace))
                {
                    SuperController.singleton.SelectController(SuperController.singleton.GetAtomByUid(selectedAction.Substring(_selectByNameCommandNamespace.Length))?.mainController);
                }
                else
                {
                    Invoke(selectedAction);
                }
                _lastSelectedAction = selectedAction;
            }
            _modeSelector.EnterNormalMode();
            return;
        }

        var query = _overlay.value.input.text;

        if (Input.GetKeyDown(KeyCode.Tab))
        {
            if (query.Length == 0 || _fuzzyFinder.matches < 2)
            {
                return;
            }
            if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
            {
                _fuzzyFinder.tabIndex = _fuzzyFinder.tabIndex == 0 ? _fuzzyFinder.matches - 1 : (_fuzzyFinder.tabIndex - 1);
            }
            else
            {
                _fuzzyFinder.tabIndex = (_fuzzyFinder.tabIndex + 1) % _fuzzyFinder.matches;
            }
        }

        var matched = _fuzzyFinder.FuzzyFind(query);

        if (!matched)
        {
            _overlay.value.Set(":");
            return;
        }

        var contextStr = "";
        IActionCommandInvoker invoker;

        if (_remoteCommandsManager.TryGetInvoker(_fuzzyFinder.current, out invoker))
        {
            var script = invoker.storable as MVRScript;
            if (script != null && script.containingAtom != null)
            {
                var atomName = script.containingAtom.name;
                if (atomName != "CoreControl")
                {
                    contextStr = $" <color=grey>[{script.containingAtom.name}]</color>";
                }
            }
        }
        _overlay.value.Set($"{_fuzzyFinder.ColorizeMatch(_fuzzyFinder.current, query)}{contextStr} ({_fuzzyFinder.tabIndex + 1}/{_fuzzyFinder.matches})");
    }