示例#1
0
        public void UpdateRect()
        {
            UIDELine line = editor.doc.LineAt(editor.cursor.posY);

            if (line == null)
            {
                return;
            }
            Vector2 screenCursorPos;

            screenCursorPos.x = line.GetScreenPosition(editor.cursor.posX) * editor.charSize.x + editor.lineNumberWidth;
            //screenCursorPos.x -= editor.doc.scroll.x;
            screenCursorPos.y = editor.cursor.posY * editor.charSize.y;
            //screenCursorPos -= editor.doc.scroll;
            float height = Mathf.Max(Mathf.Min(maxHeight, itemList.Count), 1) * editor.charSize.y;

            rect = new Rect(screenCursorPos.x, screenCursorPos.y, boxWidth, height);

            float editorWidth = editor.textEditorNoScrollBarRectZeroPos.width;

            rect.y += editor.charSize.y;

            if (rect.x + rect.width > (editorWidth + editor.doc.scroll.x) - editor.lineNumberWidth)
            {
                float subtractFactor = (rect.x + rect.width) - ((editorWidth + editor.doc.scroll.x));
                //Debug.Log((rect.x+rect.width)+" "+(editorWidth+editor.doc.scroll.x)+" "+subtractFactor);
                rect.x -= subtractFactor;
            }
            boxExpandedWidth = 0.0f;
        }
        public override void OnArrowKeyMoveCursor(Vector2 pos)
        {
            UIDELine line = editor.doc.RealLineAt((int)pos.y);

            if (line == null)
            {
                return;
            }
            UIDEElement element = line.GetElementAt((int)pos.x);

            if (element == null)
            {
                return;
            }
            if (element.tokenDef.isActualCode == true)
            {
                char c = (char)0;
                if (pos.x < line.rawText.Length)
                {
                    c = line.rawText[(int)pos.x];
                }
                if (c == ';' || c == '{' || c == '}')
                {
                    UpdateChainResolver();
                }
            }
            if (conservativeParsing && editor.lastModifyTime > lastReparseTime)
            {
                Reparse();
            }
        }
示例#3
0
        public bool OnPreRenderLine(UIDELine line)
        {
            if (currentFileLogEntry != null && line.index == currentFileLogEntry.line - 1)
            {
                Rect logLineRect = editor.actualTextAreaRect;
                logLineRect.x      = editor.doc.scroll.x;
                logLineRect.height = editor.charSize.y;
                logLineRect.y      = (line.index) * editor.charSize.y;

                string   lowerLogType = currentFileLogEntry.logType.ToLower();
                GUIStyle style        = lineErrorStyle;
                Color    color        = editor.editorWindow.theme.errorColor;
                if (lowerLogType == "warning")
                {
                    color = editor.editorWindow.theme.warningColor;
                }
                else if (lowerLogType == "assert" || lowerLogType == "unknown assert")
                {
                    color = editor.editorWindow.theme.assertColor;
                }
                GUI.color = color;
                GUI.Box(logLineRect, "", style);
                GUI.color = Color.white;
            }
            return(false);
        }
示例#4
0
        public bool OnPreRenderLine(UIDELine line)
        {
            if (line == null)
            {
                return(false);
            }
            ErrorDef errorDef = null;

            for (int i = 0; i < errors.Count; i++)
            {
                if (errors[i] != null && errors[i].line == line.index)
                {
                    errorDef = errors[i];
                }
            }
            if (errorDef != null)
            {
                Rect logLineRect = editor.actualTextAreaRect;
                logLineRect.x = editor.doc.scroll.x;
                float columnOffset   = line.GetScreenPosition(errorDef.column) * editor.charSize.x;
                float lineEnd        = line.GetScreenPosition(line.rawText.Length) * editor.charSize.x;
                float highlightLegth = lineEnd - columnOffset;

                logLineRect.x     += columnOffset;
                logLineRect.width  = highlightLegth;
                logLineRect.height = editor.charSize.y;
                logLineRect.y      = (line.index) * editor.charSize.y;

                if (logLineRect.Contains(Event.current.mousePosition))
                {
                    mouseOverError      = errorDef;
                    mouseOverRect       = logLineRect;
                    mouseOverRect.width = Mathf.Clamp(mouseOverRect.width, 100.0f, editor.actualTextAreaRect.width);
                }

                Rect underlineRect = logLineRect;
                underlineRect.height = errorUnderlineTex.height;
                underlineRect.y     += editor.charSize.y;
                underlineRect.y     -= underlineRect.height;

                Rect underlineUVRect = underlineRect;
                underlineUVRect.x      = 0;
                underlineUVRect.y      = 0;
                underlineUVRect.height = 1;

                underlineUVRect.width = underlineUVRect.width / (float)errorUnderlineTex.width;

                Color color = editor.editorWindow.theme.errorUnderlineColor;

                GUI.color = color;
                GUI.DrawTextureWithTexCoords(underlineRect, errorUnderlineTex, underlineUVRect);
                GUI.color = Color.white;
            }
            return(false);
        }
示例#5
0
        public UIDEElement GetCursorElement(int offset)
        {
            UIDELine line = editor.doc.LineAt(editor.cursor.posY);

            if (line != null)
            {
                UIDEElement element = line.GetElementAt(editor.cursor.posX - 1);
                return(element);
            }
            return(null);
        }
示例#6
0
        public void OnPostRenderLine(UIDELine line)
        {
            if (!show)
            {
                return;
            }
            if (findTerm != "")
            {
                string lineText       = line.rawText;
                string actualFindTerm = findTerm;
                string actualLineText = line.rawText;

                if (!useCase)
                {
                    actualFindTerm = actualFindTerm.ToLower();
                    actualLineText = actualLineText.ToLower();
                }

                List <int> searchIndexes = AllIndexesOf(actualLineText, actualFindTerm);
                if (searchIndexes.Count > 0)
                {
                    float    yPos = line.index * editor.charSize.y;
                    GUIStyle hoverHighlightStyle = editor.editorWindow.theme.GetStyle("CursorHoverHighlight");
                    //float contentHeight = hoverHighlightStyle.CalcHeight(new GUIContent("#YOLO"),100);
                    for (int i = 0; i < searchIndexes.Count; i++)
                    {
                        int   index    = searchIndexes[i];
                        int   charXPos = line.GetScreenPosition(index);
                        float xPos     = charXPos * editor.charSize.x;
                        //float xEndPos = line.GetScreenPosition(index+findTerm.Length)*editor.charSize.x;

                        bool isSameAsSelection = false;
                        if (editor.cursor.selection.actualStart == new Vector2(index, line.index) && editor.cursor.selection.actualEnd == new Vector2(index + findTerm.Length, line.index))
                        {
                            isSameAsSelection = true;
                        }
                        string inlineText = lineText.Substring(index, findTerm.Length);
                        if (!isSameAsSelection)
                        {
                            UIDEElement element = new UIDEElement();
                            element.rawText = inlineText;
                            element.line    = line;

                            editor.RenderElement(element, new Vector2(xPos, yPos), index, hoverHighlightStyle, false);
                            //float width = xEndPos-xPos;
                            //Rect r = new Rect(xPos,yPos,width,contentHeight);
                            //GUI.Box(r,"",hoverHighlightStyle);
                        }
                    }
                }
            }
        }
        private void UpdateMultilineFormattingActual(System.Object context)
        {
            try {
                UpdateMultilineFormattingGeneric();

                if (editor.editorWindow.generalSettings.GetUseCodeFolding() && parserInterface.lastSourceFile != null)
                {
                    //lock (parserInterface) {
                    bool[] newLineIsFoldable    = new bool[editor.doc.lineCount];
                    int[]  newLineFoldingLength = new int[editor.doc.lineCount];
                    ReparseActual(null);
                    List <StatementBlock> blocks = GetStatementBlocksRecursive(parserInterface.lastSourceFile.statementBlock);

                    foreach (StatementBlock block in blocks)
                    {
                        int startLine = block.startLine;
                        int endLine   = block.endLine;
                        if (startLine >= endLine)
                        {
                            continue;
                        }
                        int      foldingLength = endLine - startLine;
                        UIDELine line          = editor.doc.RealLineAt(startLine);
                        if (line == null)
                        {
                            continue;
                        }
                        newLineIsFoldable[line.index]    = true;
                        newLineFoldingLength[line.index] = foldingLength;
                    }

                    for (int i = 0; i < newLineIsFoldable.Length; i++)
                    {
                        UIDELine line = editor.doc.RealLineAt(i);
                        if (line == null)
                        {
                            continue;
                        }
                        line.isFoldable    = newLineIsFoldable[i];
                        line.foldingLength = newLineFoldingLength[i];
                    }
                    //}
                }
            }
            finally {
                //UIDEThreadPool.UnregisterThread("SRCSUS_UpdateMultilineFormatting");
            }

            //editor.editorWindow.Repaint();
        }
        public bool OnPreRenderLine(UIDELine line)
        {
            if (line == null) return false;
            ErrorDef errorDef = null;
            for (int i = 0; i < errors.Count; i++) {
                if (errors[i] != null && errors[i].line == line.index) {
                    errorDef = errors[i];
                }
            }
            if (errorDef != null) {
                Rect logLineRect = editor.actualTextAreaRect;
                logLineRect.x = editor.doc.scroll.x;
                float columnOffset = line.GetScreenPosition(errorDef.column)*editor.charSize.x;
                float lineEnd = line.GetScreenPosition(line.rawText.Length)*editor.charSize.x;
                float highlightLegth = lineEnd-columnOffset;

                logLineRect.x += columnOffset;
                logLineRect.width = highlightLegth;
                logLineRect.height = editor.charSize.y;
                logLineRect.y = (line.index)*editor.charSize.y;

                if (logLineRect.Contains(Event.current.mousePosition)) {
                    mouseOverError = errorDef;
                    mouseOverRect = logLineRect;
                    mouseOverRect.width = Mathf.Clamp(mouseOverRect.width,100.0f,editor.actualTextAreaRect.width);
                }

                Rect underlineRect = logLineRect;
                underlineRect.height = errorUnderlineTex.height;
                underlineRect.y += editor.charSize.y;
                underlineRect.y -= underlineRect.height;

                Rect underlineUVRect = underlineRect;
                underlineUVRect.x = 0;
                underlineUVRect.y = 0;
                underlineUVRect.height = 1;

                underlineUVRect.width = underlineUVRect.width/(float)errorUnderlineTex.width;

                Color color = editor.editorWindow.theme.errorUnderlineColor;

                GUI.color = color;
                GUI.DrawTextureWithTexCoords(underlineRect,errorUnderlineTex,underlineUVRect);
                GUI.color = Color.white;
            }
            return false;
        }
示例#9
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);
            }
        }
示例#10
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;
            }
        }
        public override void OnRebuildLineElements(UIDELine line)
        {
            base.OnRebuildLineElements(line);

            wantsMultiLineFormattingUpdate = true;
        }
示例#13
0
        public bool OnPreRenderLine(UIDELine line)
        {
            if (currentFileLogEntry != null && line.index == currentFileLogEntry.line-1) {
                Rect logLineRect = editor.actualTextAreaRect;
                logLineRect.x = editor.doc.scroll.x;
                logLineRect.height = editor.charSize.y;
                logLineRect.y = (line.index)*editor.charSize.y;

                string lowerLogType = currentFileLogEntry.logType.ToLower();
                GUIStyle style = lineErrorStyle;
                Color color = editor.editorWindow.theme.errorColor;
                if (lowerLogType == "warning") {
                    color = editor.editorWindow.theme.warningColor;
                }
                else if (lowerLogType == "assert" || lowerLogType == "unknown assert") {
                    color = editor.editorWindow.theme.assertColor;
                }
                GUI.color = color;
                GUI.Box(logLineRect,"",style);
                GUI.color = Color.white;
            }
            return false;
        }
示例#14
0
        public override void OnRebuildLineElements(UIDELine line)
        {
            base.OnRebuildLineElements(line);

            wantsMultiLineFormattingUpdate = true;
        }
示例#15
0
        public void UpdateToolTipRect()
        {
            UIDELine line = editor.doc.LineAt((int)toolTipPos.y);

            if (line == null)
            {
                return;
            }

            GUIStyle tooltipStyle = skin.GetStyle("ToolTip");

            toolTipMaxWidth = editor.textEditorNoScrollBarRectZeroPos.width - 100.0f;
            toolTipMaxWidth = Mathf.Max(toolTipMaxWidth, 100.0f);

            GUIContent content = new GUIContent(tooltipText);

            if (currentTooltip != null && currentTooltip.item != null)
            {
                Texture2D icon = editor.editorWindow.theme.GetLanguageIcon(currentTooltip.item.GetLanguageIconName());
                if (icon != null)
                {
                    content.image = icon;
                }
            }

            //Create a tmp style to check the size without wordwrap.
            GUIStyle tooltipStyleTMP = new GUIStyle(tooltipStyle);

            tooltipStyleTMP.wordWrap = false;
            Vector2 clacedSize   = tooltipStyleTMP.CalcSize(content);
            float   desiredWidth = clacedSize.x;

            if (desiredWidth > toolTipMaxWidth)
            {
                desiredWidth = toolTipMaxWidth;
            }

            float height = tooltipStyle.CalcHeight(content, desiredWidth);

            tooltipRect.x      = 0;
            tooltipRect.y      = 0;
            tooltipRect.width  = desiredWidth;
            tooltipRect.height = height;

            Vector2 screenCursorPos;

            screenCursorPos.x = line.GetScreenPosition((int)toolTipPos.x) * editor.charSize.x + editor.lineNumberWidth;
            screenCursorPos.y = toolTipPos.y * editor.charSize.y;

            screenCursorPos.x -= editor.doc.scroll.x;
            screenCursorPos.y -= editor.doc.scroll.y;

            tooltipRect.x = screenCursorPos.x - (desiredWidth * 0.5f);
            tooltipRect.y = screenCursorPos.y - (height + editor.charSize.y * 0.5f);

            float editorWidth = editor.textEditorNoScrollBarRectZeroPos.width;

            if (tooltipRect.x + tooltipRect.width > (editorWidth))
            {
                float subtractFactor = (tooltipRect.x + tooltipRect.width) - (editorWidth);
                tooltipRect.x -= subtractFactor;
            }
            if (tooltipRect.x < editor.lineNumberWidth)
            {
                tooltipRect.x = editor.lineNumberWidth;
            }
            wantsTooltipRectUpdate = false;
        }
示例#16
0
        public Vector2 FindNext(Vector2 pos, int dir, bool wrap)
        {
            Vector2 outPos = new Vector2(-1, -1);

            if (dir == 0)
            {
                return(outPos);
            }
            if (findTerm == "")
            {
                return(outPos);
            }

            dir = (int)Mathf.Sign(dir);
            string actualFindTerm = findTerm;

            if (!useCase)
            {
                actualFindTerm = actualFindTerm.ToLower();
            }

            int startLine    = (int)pos.y;
            int lineToStopAt = editor.actualLinesToRender.Count - 1;

            if (dir == -1)
            {
                lineToStopAt = 0;
            }
            bool hasWrapped = false;

            for (int i = (int)pos.y; i < editor.actualLinesToRender.Count; i += dir)
            {
                UIDELine line           = editor.doc.LineAt(i);
                string   actualLineText = line.rawText;
                if (!useCase)
                {
                    actualLineText = actualLineText.ToLower();
                }

                int index = -1;
                if (dir == 1)
                {
                    index = actualLineText.IndexOf(actualFindTerm, (int)pos.x);
                }
                else
                {
                    index = actualLineText.LastIndexOf(actualFindTerm, (int)pos.x);
                }
                if (index != -1)
                {
                    outPos = new Vector2(index, i);
                    break;
                }

                bool lineIsStopLine = false;
                if (dir == 1)
                {
                    lineIsStopLine = i >= lineToStopAt;
                }
                else
                {
                    lineIsStopLine = i <= lineToStopAt;
                }
                if (wrap && lineIsStopLine)
                {
                    if (hasWrapped)
                    {
                        break;
                    }
                    if (dir == 1)
                    {
                        i = 0;
                    }
                    else
                    {
                        i = editor.actualLinesToRender.Count - 1;
                    }
                    lineToStopAt = startLine;
                    hasWrapped   = true;
                }
                if (dir == 1)
                {
                    pos.x = 0;
                }
                else
                {
                    if (i - 1 < 0)
                    {
                        break;
                    }
                    UIDELine nextLine = editor.doc.LineAt(i - 1);
                    pos.x = nextLine.rawText.Length;
                }
            }
            return(outPos);
        }
示例#17
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();
        }
示例#18
0
        public void OnPostRenderLine(UIDELine line)
        {
            if (!show) return;
            if (findTerm != "") {
                string lineText = line.rawText;
                string actualFindTerm = findTerm;
                string actualLineText = line.rawText;

                if (!useCase) {
                    actualFindTerm = actualFindTerm.ToLower();
                    actualLineText = actualLineText.ToLower();
                }

                List<int> searchIndexes = AllIndexesOf(actualLineText,actualFindTerm);
                if (searchIndexes.Count > 0) {
                    float yPos = line.index*editor.charSize.y;
                    GUIStyle hoverHighlightStyle = editor.editorWindow.theme.GetStyle("CursorHoverHighlight");
                    //float contentHeight = hoverHighlightStyle.CalcHeight(new GUIContent("#YOLO"),100);
                    for (int i = 0; i < searchIndexes.Count; i++) {
                        int index = searchIndexes[i];
                        int charXPos = line.GetScreenPosition(index);
                        float xPos = charXPos*editor.charSize.x;
                        //float xEndPos = line.GetScreenPosition(index+findTerm.Length)*editor.charSize.x;

                        bool isSameAsSelection = false;
                        if (editor.cursor.selection.actualStart == new Vector2(index,line.index) && editor.cursor.selection.actualEnd == new Vector2(index+findTerm.Length,line.index)) {
                            isSameAsSelection = true;
                        }
                        string inlineText = lineText.Substring(index,findTerm.Length);
                        if (!isSameAsSelection) {
                            UIDEElement element = new UIDEElement();
                            element.rawText = inlineText;
                            element.line = line;

                            editor.RenderElement(element, new Vector2(xPos,yPos),index,hoverHighlightStyle,false);
                            //float width = xEndPos-xPos;
                            //Rect r = new Rect(xPos,yPos,width,contentHeight);
                            //GUI.Box(r,"",hoverHighlightStyle);
                        }
                    }
                }
            }
        }
        public override CompletionMethod[] GetMethodOverloads(Vector2 pos)
        {
            //Vector2 originalPos = pos;
            if (parserInterface.lastSourceFile == null)
            {
                Reparse();
            }

            pos = editor.doc.IncrementPosition(pos, -1);
            pos = editor.doc.IncrementPosition(pos, -1);
            pos = editor.doc.GoToEndOfWhitespace(pos, -1);

            //char nextChar = editor.doc.GetCharAt(pos);
            if (editor.doc.GetCharAt(pos) == '>')
            {
                ExpressionResolver.editor = editor;
                pos = ExpressionResolver.SimpleMoveToEndOfScope(pos, -1, ExpressionBracketType.Generic);
                pos = editor.doc.GoToEndOfWhitespace(pos, -1);
                if (useUnityscript)
                {
                    if (editor.doc.GetCharAt(pos) == '.')
                    {
                        pos = editor.doc.IncrementPosition(pos, -1);
                    }
                }
                pos = editor.doc.GoToEndOfWhitespace(pos, -1);
                //GameObject go;
                //go.GetComponent<Vector3>();
            }
            Vector2 endWordPos = pos;

            pos = editor.doc.GoToEndOfWord(pos, -1);
            Vector2 startWordPos = editor.doc.IncrementPosition(pos, 1);

            pos = editor.doc.GoToEndOfWhitespace(pos, -1);
            //

            //Debug.Log(editor.doc.GetCharAt(pos));
            bool hasDot = false;

            if (editor.doc.GetCharAt(pos) == '.')
            {
                if (useUnityscript)
                {
                    if (editor.doc.GetCharAt(editor.doc.IncrementPosition(pos, 1)) != '<')
                    {
                        hasDot = true;
                    }
                }
                else
                {
                    hasDot = true;
                }
            }

            UIDELine startLine    = editor.doc.RealLineAt((int)startWordPos.y);
            string   functionName = startLine.rawText.Substring((int)startWordPos.x, ((int)endWordPos.x - (int)startWordPos.x) + 1);

            pos = editor.doc.IncrementPosition(pos, -1);
            pos = editor.doc.GoToEndOfWhitespace(pos, -1);

            string str = editor.syntaxRule.ResolveExpressionAt(pos, -1);

            if (useUnityscript)
            {
                str = str.Replace(".<", "<");
            }
            //Debug.Log(str);

            CompletionMethod[] methods          = new CompletionMethod[0];
            ChainResolver      sigChainResolver = new ChainResolver(editor, pos);

            //Handle constructors
            bool isDirectConstructor   = str == "new|";
            bool isIndirectConstructor = !isDirectConstructor && str.StartsWith("new|");

            if (isIndirectConstructor && hasDot)
            {
                isIndirectConstructor = false;
            }
            if (isIndirectConstructor)
            {
                ChainItem item = null;
                item = sigChainResolver.ResolveChain(str + "." + functionName);
                if (item == null || item.finalLinkType == null)
                {
                    return(methods);
                }
                methods = sigChainResolver.GetConstructors(item.finalLinkType);
                return(methods);
            }
            else if (isDirectConstructor)
            {
                ChainItem item = null;
                item = sigChainResolver.ResolveChain(functionName);
                if (item == null || item.finalLinkType == null)
                {
                    return(methods);
                }
                methods = sigChainResolver.GetConstructors(item.finalLinkType);
                return(methods);
            }

            System.Type type     = sigChainResolver.reflectionDB.currentType;
            bool        isStatic = false;

            if (hasDot)
            {
                ChainItem item = null;
                item = sigChainResolver.ResolveChain(str, false);
                if (item == null || item.finalLinkType == null)
                {
                    return(methods);
                }
                isStatic = item.finalLink.isStatic;
                type     = item.finalLinkType;
            }

            methods = sigChainResolver.GetMethodOverloads(type, functionName, isStatic);

            return(methods);
        }
        public override CompletionItem[] GetChainCompletionItems()
        {
            if (parserInterface.lastSourceFile == null)
            {
                Reparse();
            }

            if (conservativeParsing && isCreatingChainResolver)
            {
                int i = 0;
                while (isCreatingChainResolver && i < 100)
                {
                    Thread.Sleep(10);
                    i++;
                }
            }

            if (conservativeParsing)
            {
                UpdateChainResolverActual(null);
            }

            List <CompletionItem> items = new List <CompletionItem>();

            Vector2 previousCharPos = editor.cursor.GetVectorPosition();

            previousCharPos = editor.doc.IncrementPosition(previousCharPos, -1);

            UIDELine    line    = editor.doc.RealLineAt((int)previousCharPos.y);
            UIDEElement element = line.GetElementAt((int)previousCharPos.x);

            Vector2 expressionStartPos = previousCharPos;

            bool lastCharIsDot = element.tokenDef.HasType("Dot");

            if (lastCharIsDot)
            {
                expressionStartPos = editor.doc.IncrementPosition(expressionStartPos, -1);
            }
            else
            {
                int elementPos = line.GetElementStartPos(element);
                if (elementPos >= 2)
                {
                    element = line.GetElementAt(elementPos - 1);
                    if (element.tokenDef.HasType("Dot"))
                    {
                        expressionStartPos.x = elementPos - 2;
                    }
                }
            }

            ChainItem item = null;
            string    str  = ResolveExpressionAt(expressionStartPos, -1);

            if (useUnityscript)
            {
                str = str.Replace(".<", "<");
            }
            //Debug.Log(str);

            VerifyChainResolver();

            item = chainResolver.ResolveChain(str);

            if (item != null)
            {
                items = item.autoCompleteItems;
            }

            return(items.ToArray());
        }