Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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;
        }
        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;
            }
        }
Ejemplo n.º 4
0
        public void UpdateAutoComplete(string text, bool isBackspace)
        {
            if (!isEnabled)
            {
                return;
            }
            if (text == "\n" || text == "\b" || (text == "" && !isBackspace))
            {
                return;
            }

            if (text.Length > 1)
            {
                HideBox();
                return;
            }

            UIDELine    line    = editor.doc.LineAt(editor.cursor.posY);
            UIDEElement element = GetCursorElement();

            if (!genericMode)
            {
                if (text == "(")
                {
                    StartShowTooltip(editor.cursor.GetVectorPosition(), true);
                    dontShowToolTipAgain = true;
                    cancelTooltip        = false;
                }
                if (text == ")" || isBackspace)
                {
                    if (isShowingMethodOverloadTooltip)
                    {
                        HideToolTip();
                    }
                    if (!isBackspace)
                    {
                        cancelTooltip = true;
                    }
                }
                if (text == " " && (editor.extension == ".cs" || editor.extension == ".js"))
                {
                    Vector2 lastWordPos = editor.doc.IncrementPosition(editor.cursor.GetVectorPosition(), -1);
                    lastWordPos = editor.doc.IncrementPosition(lastWordPos, -1);
                    //lastWordPos = editor.doc.GoToEndOfWhitespace(lastWordPos,-1);
                    UIDEElement newElement = editor.doc.GetElementAt(lastWordPos);
                    if (newElement != null && newElement.rawText == "new")
                    {
                        Vector2 newWordStart = lastWordPos;
                        newWordStart.x = line.GetElementStartPos(newElement);
                        Vector2 leadingCharPos = editor.doc.IncrementPosition(newWordStart, -1);
                        leadingCharPos = editor.doc.GoToEndOfWhitespace(leadingCharPos, -1);
                        char leadingChar = editor.doc.GetCharAt(leadingCharPos);
                        if (leadingChar == '=')
                        {
                            Vector2 wordStartPos = editor.doc.IncrementPosition(leadingCharPos, -1);
                            wordStartPos = editor.doc.GoToEndOfWhitespace(wordStartPos, -1);
                            string      str = "";
                            UIDEElement firstNonWhitespaceElement = line.GetFirstNonWhitespaceElement();
                            if (editor.extension == ".js" && firstNonWhitespaceElement != null && firstNonWhitespaceElement.rawText == "var")
                            {
                                Vector2 typeStart = editor.doc.GoToNextRealChar(wordStartPos, ':', -1);
                                if (typeStart.y == wordStartPos.y)
                                {
                                    typeStart = editor.doc.IncrementPosition(typeStart, 1);
                                    typeStart = editor.doc.GoToEndOfWhitespace(typeStart, 1);

                                    if (typeStart.x < wordStartPos.x)
                                    {
                                        str = line.rawText.Substring((int)typeStart.x, (int)wordStartPos.x - (int)typeStart.x + 1);
                                        str = str.Replace(" ", "");
                                        str = str.Replace("\t", "");
                                        str = str.Replace(".<", "<");
                                    }
                                }
                            }
                            else
                            {
                                str = editor.syntaxRule.ResolveExpressionAt(wordStartPos, -1);
                            }
                            ChainResolver sigChainResolver = new ChainResolver(editor, editor.cursor.GetVectorPosition());

                            ChainItem item = null;
                            item = sigChainResolver.ResolveChain(str, false);

                            if (item != null && item.finalLinkType != null)
                            {
                                CompletionItem cItem = new CompletionItem(item.finalLinkType);
                                if (cItem != null)
                                {
                                    string[] usingNamespaces = editor.syntaxRule.GetNamespacesVisibleInCurrentScope(editor.cursor.GetVectorPosition());
                                    string[] chainNamespaces = editor.syntaxRule.GetNamespaceChain(editor.cursor.GetVectorPosition());
                                    cItem.name = cItem.PrettyFormatType(false, usingNamespaces, chainNamespaces);
                                    //Debug.Log(cItem.genericArguments[0].resultingType);
                                    itemList = new List <CompletionItem>();
                                    itemList.Add(cItem);
                                    selectedIndex = 0;
                                    ShowBox();
                                }
                            }

                            return;
                        }
                    }
                }
            }

            if (element != null)
            {
                isDot        = element.tokenDef.HasType("Dot");
                isWord       = element.tokenDef.HasType("Word");
                isWhiteSpace = element.tokenDef.HasType("WhiteSpace");
                bool isDotOrWord = isDot || isWord;

                autoCompleteKey = element.rawText;
                int  elementPos = line.GetElementStartPos(element);
                bool isChain    = false;

                if (isDot)
                {
                    isChain = true;
                }
                else
                {
                    if (elementPos > 0 && isWord)
                    {
                        UIDEElement previousElement = line.GetElementAt(elementPos - 1);
                        if (previousElement != null)
                        {
                            if (previousElement.tokenDef.HasType("Dot"))
                            {
                                isChain = true;
                            }
                        }
                    }
                }

                if (genericMode)
                {
                    isChain = false;
                }

                //bool newCharIsWhitespace = text == " "||text == "\t";

                if (visible && isWord)
                {
                    //continue an existing autocomplete
                }
                if (!visible && isDotOrWord && !isBackspace)
                {
                    TryStartUpdateAutoCompleteList(isChain);
                }
                if (visible && !isDotOrWord)
                {
                    HideBox();
                }
                if (visible && isBackspace && !isDotOrWord)
                {
                    HideBox();
                }
                //For performance on OSX.
                if (Application.platform == RuntimePlatform.OSXEditor)
                {
                    if (visible && isBackspace)
                    {
                        HideBox();
                        visible = false;
                    }
                }
                if (visible && autoCompleteKey != "")
                {
                    TryStartUpdateAutoCompleteList(isChain);
                }
                if (visible && isDot)
                {
                    UpdateRect();
                }
                //TryStartUpdateAutoCompleteList();
            }
            else
            {
                if (visible)
                {
                    HideBox();
                }
            }

            editor.editorWindow.Repaint();
        }