Beispiel #1
0
        public static void Update()
        {
            if (SRENotSupported)
            {
                return;
            }

            UpdateCaret(out bool caretMoved);

            if (!settingCaretCoroutine && EnableSuggestions && AutoCompleteModal.CheckEscape(Completer))
            {
                OnAutocompleteEscaped();
                return;
            }

            if (!settingCaretCoroutine && EnableSuggestions && caretMoved)
            {
                AutoCompleteModal.Instance.ReleaseOwnership(Completer);
                //Completer.CheckAutocompletes();
            }

            if (EnableCtrlRShortcut &&
                (InputManager.GetKey(KeyCode.LeftControl) || InputManager.GetKey(KeyCode.RightControl)) &&
                InputManager.GetKeyDown(KeyCode.R) &&
                timeOfLastCtrlR.OccuredEarlierThanDefault())
            {
                timeOfLastCtrlR = Time.realtimeSinceStartup;
                Evaluate(Panel.Input.Text);
            }
        }
        // Invoked at most once per frame
        private static void OnInputChanged(string value)
        {
            if (SRENotSupported)
            {
                return;
            }

            // prevent escape wiping input
            if (InputManager.GetKeyDown(KeyCode.Escape))
            {
                Input.Text = previousInput;

                if (EnableSuggestions && AutoCompleteModal.CheckEscape(Completer))
                {
                    OnAutocompleteEscaped();
                }

                return;
            }

            previousInput = value;

            if (EnableSuggestions && AutoCompleteModal.CheckEnter(Completer))
            {
                OnAutocompleteEnter();
            }

            if (!settingCaretCoroutine)
            {
                if (EnableAutoIndent)
                {
                    DoAutoIndent();
                }
            }

            var inStringOrComment = HighlightVisibleInput();

            if (!settingCaretCoroutine)
            {
                if (EnableSuggestions)
                {
                    if (inStringOrComment)
                    {
                        AutoCompleteModal.Instance.ReleaseOwnership(Completer);
                    }
                    else
                    {
                        Completer.CheckAutocompletes();
                    }
                }
            }

            UpdateCaret(out _);
        }
Beispiel #3
0
        private static void UpdateCaret(out bool caretMoved)
        {
            int prevCaret = LastCaretPosition;

            caretMoved = false;

            // Override up/down arrow movement when autocompleting
            if (EnableSuggestions && AutoCompleteModal.CheckNavigation(Completer))
            {
                Input.Component.caretPosition = LastCaretPosition;
                return;
            }

            if (Input.Component.isFocused)
            {
                LastCaretPosition = Input.Component.caretPosition;
                caretMoved        = LastCaretPosition != prevCaret;
            }

            if (Input.Text.Length == 0)
            {
                return;
            }

            // If caret moved, ensure caret is visible in the viewport
            if (caretMoved)
            {
                var charInfo = Input.TextGenerator.characters[LastCaretPosition];
                var charTop  = charInfo.cursorPos.y;
                var charBot  = charTop - CSCONSOLE_LINEHEIGHT;

                var viewportMin = Input.Rect.rect.height - Input.Rect.anchoredPosition.y - (Input.Rect.rect.height * 0.5f);
                var viewportMax = viewportMin - Panel.InputScroll.ViewportRect.rect.height;

                float diff = 0f;
                if (charTop > viewportMin)
                {
                    diff = charTop - viewportMin;
                }
                else if (charBot < viewportMax)
                {
                    diff = charBot - viewportMax;
                }

                if (Math.Abs(diff) > 1)
                {
                    var rect = Input.Rect;
                    rect.anchoredPosition = new Vector2(rect.anchoredPosition.x, rect.anchoredPosition.y - diff);
                }
            }
        }