예제 #1
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);
            }
        }
예제 #2
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;
        }