コード例 #1
0
        public void InsertText(string newText, bool smartButtony = false)
        {
            if (theInputField.isFocused)
            {
                // If selection, replace selection
                // Else, just insert
                int    start = Mathf.Min(theInputField.selectionAnchorPosition, theInputField.selectionFocusPosition);
                int    end   = Mathf.Max(theInputField.selectionAnchorPosition, theInputField.selectionFocusPosition);
                string checkText;

                if (start == end)
                {
                    // No selection
                    checkText = theInputField.text.Insert(start, newText);
                }
                else
                {
                    // Yes selection
                    checkText = theInputField.text.Substring(0, start) + newText + theInputField.text.Substring(end);
                }

                // Try adding extra newline if it's the end of the line
                string checkText2 = null;
                string after      = checkText.Substring(start + newText.Length);
                if (smartButtony && (after.Length == 0 || after[0] == '\n'))
                {
                    int indent = IDEPARSER.getIndentLevel(start, checkText);

                    // Add newline directly
                    if (start > 0 && checkText[start - 1] == ':')
                    {
                        checkText = checkText.Insert(start, "\n" + new string('\t', indent));
                        start    += 1 + indent;
                    }

                    checkText2 = checkText.Insert(start + newText.Length, "\n" + new string('\t', indent));
                    start     += 1 + indent;
                }

                // Check if it fits
                if (checkText2 == null || !IDETextManipulation.validateText(checkText2, codeRowsLimit, maxChars))
                {
                    checkText2 = null;
                    if (!IDETextManipulation.validateText(checkText, codeRowsLimit, maxChars))
                    {
                        checkText = null;
                    }
                }

                // One of them succeded
                if (checkText2 != null || checkText != null)
                {
                    inserting = true;

                    setNewCaretPos(start + newText.Length);
                    theInputField.text = checkText2 ?? checkText;
                }
            }
        }
コード例 #2
0
        private char MyValidate(char c, int charIndex)
        {
            if (inserting)
            {
                return(c);
            }

            lastCharInsertIndex = charIndex;

            return(IDETextManipulation.MyValidate(c, charIndex, isPasting(), toAddLevels, theInputField.text, this));
        }
コード例 #3
0
        private void addAutoIndent()
        {
            string startString = theInputField.text;

            foreach (IndentLevel l in toAddLevels)
            {
                startString = startString.Insert(l.caretPos, l.indentText);
            }

            if (IDETextManipulation.validateText(startString, codeRowsLimit, maxChars))
            {
                inserting          = true;
                theInputField.text = startString;
            }

            toAddLevels.Clear();
        }
コード例 #4
0
        //Cheks if the current input will fit into the speciefied borders!
        //Restricted by amount of rows in Y
        //and by maxChars in X
        private void doValidateInput()
        {
            if (IDETextManipulation.validateText(theInputField.text, codeRowsLimit, maxChars))
            {
                lastText = theInputField.text;
                ColorCodeDaCode();
            }
            else
            {
                inserting                   = true;
                theInputField.text          = lastText;
                theInputField.caretPosition = lastCharInsertIndex;
            }

            Progress.Instance.LevelData[PMWrapper.CurrentLevel.id].MainCode = PMWrapper.mainCode;
            FocusCursor();
            theLineMarker.removeErrorMessage();
        }
コード例 #5
0
        //Cheks if the current input will fit into the speciefied borders!
        //Restricted by amount of rows in Y
        //and by maxChars in X
        private void doValidateInput()
        {
            if (IDETextManipulation.validateText(theInputField.text, codeRowsLimit, maxChars))
            {
                lastText = theInputField.text;
                ColorCodeDaCode();
            }
            else
            {
                inserting                   = true;
                theInputField.text          = lastText;
                theInputField.caretPosition = lastCharInsertIndex;
            }

            FocusCursor();

            SaveData.SaveMainCode();

            theLineMarker.removeErrorMessage();
        }