public void OnColon()
        {
            UIDELine line = editor.doc.RealLineAt((int)editor.cursor.posY);

            if (line == null)
            {
                return;
            }
            if (editor.cursor.posY < line.rawText.Length)
            {
                return;
            }
            UIDEElement firstElement = line.GetFirstNonWhitespaceElement();

            if (firstElement == null)
            {
                return;
            }

            if (firstElement.tokenDef.HasType("Word") && firstElement.rawText == "case")
            {
                if (line.rawText[0] == '\t')
                {
                    //string originalText = lines[i].rawText;
                    line.rawText = line.rawText.Substring(1);
                    line.RebuildElements();
                }
                else if (line.rawText[0] == ' ')
                {
                    int tabSize = editor.editorWindow.textSettings.GetTabSize();
                    //string originalText = lines[i].rawText;
                    for (int j = 0; j < tabSize; j++)
                    {
                        if (line.rawText.Length <= 0 || line.rawText[0] != ' ')
                        {
                            break;
                        }
                        line.rawText = line.rawText.Substring(1);
                    }
                    line.RebuildElements();
                }
                editor.cursor.posX = line.rawText.Length;
            }
        }
示例#2
0
        public void OnNewLine()
        {
            if (editor.cursor.posY <= 0)
            {
                return;
            }

            UIDELine line         = editor.doc.LineAt(editor.cursor.posY);
            UIDELine previousLine = editor.doc.GetLastNoneWhitespaceOrCommentLine(editor.cursor.posY - 1);

            if (previousLine == null)
            {
                return;
            }
            UIDEElement firstElement         = previousLine.GetFirstNonWhitespaceElement();
            int         previousLineStartPos = previousLine.GetElementStartPos(firstElement);
            int         screenPos            = previousLine.GetScreenPosition(previousLineStartPos);
            UIDEElement lastElement          = previousLine.GetLastNonWhitespaceElement();

            string originalText = line.rawText;
            int    tabCount     = screenPos / 4;

            if (lastElement != null && lastElement.rawText == "{")
            {
                tabCount += 1;
            }
            line.rawText = line.GetTrimmedWhitespaceText();
            for (int i = 0; i < tabCount; i++)
            {
                line.rawText = "\t" + line.rawText;
            }
            line.RebuildElements();

            Vector2 oldCursorPos = editor.cursor.GetVectorPosition();

            editor.cursor.posX = tabCount;
            Vector2 newCursorPos = editor.cursor.GetVectorPosition();

            //add another undo with the same name as the previous one so it gets grouped.
            if (editor.undoManager.undos.Count > 0)
            {
                string undoName = editor.undoManager.undos[editor.undoManager.undos.Count - 1].groupID;
                editor.undoManager.RegisterUndo(undoName, UIDEUndoType.LineModify, line.index, originalText, line.rawText, oldCursorPos, newCursorPos);
            }
        }
示例#3
0
        public void OnCloseCurly()
        {
            if (editor.cursor.posY <= 0)
            {
                return;
            }
            UIDELine line         = editor.doc.LineAt(editor.cursor.posY);
            UIDELine previousLine = editor.doc.GetLastNoneWhitespaceOrCommentLine(editor.cursor.posY - 1);

            if (previousLine == line)
            {
                return;
            }

            if (!line.IsLineWhitespace())
            {
                return;
            }

            UIDEElement firstElement         = previousLine.GetFirstNonWhitespaceElement();
            int         previousLineStartPos = previousLine.GetElementStartPos(firstElement);
            int         screenPos            = previousLine.GetScreenPosition(previousLineStartPos);
            UIDEElement lastElement          = previousLine.GetLastNonWhitespaceElement();

            int tabCount = screenPos / 4;

            if (lastElement != null)
            {
                if (lastElement.tokenDef.HasType("LineEnd"))
                {
                    tabCount -= 1;
                }
            }
            tabCount     = Mathf.Max(tabCount, 0);
            line.rawText = line.GetTrimmedWhitespaceText();
            for (int i = 0; i < tabCount; i++)
            {
                line.rawText = "\t" + line.rawText;
            }

            //line.rawText += startingText;
            line.RebuildElements();
            editor.cursor.posX = tabCount;
        }