/// <summary>
        /// if downkey is pressed and intellisence is being displayed: enters intelliselect
        /// otherwise executes if Return is pressed.
        /// </summary>
        public static void Update_Typing()
        {
            if (IsKeyDown(KeyCode.DownArrow) && IntelliSenceHelp.Any())
            {
                Enter_IntelliSelect();
            }
            else if (IsKeyDown(KeyCode.Tab) && IntelliSenceHelp.Count > 0)
            {
                SelectedHelp = 0;
                UseIntelliSelection();
                return;
            }
            else if (IsKeyDown(KeyCode.Return) || IsKeyDown(KeyCode.KeypadEnter))
            {
                // Replace code with selected history element.
                Exit_Typing();
                Execute();
                return;
            }
            else if (IsKeyDown(KeyCode.Escape))
            {
                DisplayHelp = false;
            }

            var parseResult = Parser.ParseAssignment(Code);

            if (IntelliSenceLastCode != parseResult.ExpressionString)
            {
                DisplayHelp          = true;
                IntelliSenceLastCode = parseResult.ExpressionString;
                IntelliSenceHelp     = IntellisenseProvider.Intellisense(Code).ToList();
                SelectedHelp         = -1;
                Repaint();
            }
        }
 /// <summary>
 /// Signals the end of intelliselection.
 /// Adds the chosen intelliSence item to the current code string and replaces it.
 /// </summary>
 public static void UseIntelliSelection()
 {
     ReplacementCode = ReplacementString();
     if (ReplacementCode != Code)
     {
         IntelliSenceHelp.Clear();
         ShouldReplaceCode = true;
         SelectedHelp      = -1;
     }
 }
        public static string ReplacementString()
        {
            if (SelectedHelp < 0 || SelectedHelp >= IntelliSenceHelp.Count(i => !i.IsMethodOverload))
            {
                return(Code);
            }

            var completion = IntelliSenceHelp[SelectedHelp];

            if (IntelliSenceHelp.Any(i => i.IsMethodOverload))
            {
                completion = IntelliSenceHelp.Where(i => !i.IsMethodOverload).ToArray()[SelectedHelp];
            }
            return(Code.Substring(0, completion.Start) + completion.ReplaceString + Code.Substring(completion.End + 1));
        }