Пример #1
0
        /// <summary>
        /// 获取指令补全
        /// </summary>
        /// <param name="currentInput">当前的指令输入</param>
        /// <returns></returns>
        public static InputAttribution GetInstructionCompletion(InputAttribution currentInput)
        {
            if (string.IsNullOrEmpty(currentInput.content))
            {
                return(currentInput);
            }
            string targetInstructionLeft, targetInstructionPart, targetInstructionRight;

            GetInstructionCompletionDepart(currentInput, out targetInstructionLeft, out targetInstructionPart, out targetInstructionRight);
            if (string.IsNullOrEmpty(targetInstructionPart))
            {
                return(currentInput);
            }
            InputAttribution retn = currentInput; retn.selectEmpty = true;
            string           cp   = "";

            switch (GetInstructionCompletionPartType(targetInstructionPart))
            {
            case InstructionType.STARTUP:
                cp = AInstruction_Startup.GetCompletion(targetInstructionPart);
                break;

            case InstructionType.MACRO:
                cp = AInstruction_Macro.GetCompletion(targetInstructionPart);
                break;

            case InstructionType.CONST:
                cp = AConstQuote.GetCompletion(targetInstructionPart);
                break;

            case InstructionType.BUILDIN:
                break;
            }

            if (!string.IsNullOrEmpty(cp))
            {
                retn.content     = targetInstructionLeft + cp + targetInstructionRight;
                retn.selectStart = retn.caretPosition = currentInput.caretPosition;
                retn.selectEnd   = retn.selectStart + cp.Length - targetInstructionPart.Length - 1;
                retn.selectEmpty = retn.selectEnd <= 0 || retn.selectEnd < retn.selectStart;
            }

            // Check const-instruction completion at last.
            if (retn.selectEmpty)
            {
                cp               = AConstInstruction.GetCompletion(targetInstructionPart);
                retn.content     = targetInstructionLeft + cp + targetInstructionRight;
                retn.selectStart = retn.caretPosition = currentInput.caretPosition;
                retn.selectEnd   = retn.selectStart + cp.Length - targetInstructionPart.Length - 1;
                retn.selectEmpty = retn.selectEnd <= 0 || retn.selectEnd < retn.selectStart;
            }

            return(retn);
        }
Пример #2
0
        public static void GetInstructionCompletionDepart(InputAttribution input, out string targetLeft, out string target, out string targetRight)
        {
            int blankBias = 1;
            int targetInstructionStart = input.content.Substring(0, input.caretPosition).IndexOf(" ");

            if (targetInstructionStart == -1)
            {
                targetInstructionStart = blankBias = 0;
            }
            target      = input.content.Substring(targetInstructionStart + blankBias, input.caretPosition - targetInstructionStart - blankBias);
            targetLeft  = input.content.Substring(0, targetInstructionStart + blankBias);
            targetRight = input.content.Substring(input.caretPosition) ?? "";
        }