Ejemplo n.º 1
0
        public Position GetCaretPositionUnderMouseCursor(Vector2 cursorPosition)
        {
            if (cursorPosition.x < ViewPort.x || cursorPosition.x > ViewPort.xMax)
            {
                return(new Position(-1, -1));
            }

            var row = GetRow(cursorPosition.y);

            if (row >= LineCount)
            {
                row = LineCount - 1;
            }

            var rect = GetLineRect(row);

            rect.x += CodeOffset;

            List <int> tabSizes;
            string     renderText = Whitespace.FormatBaseText(Line(row).Text, out tabSizes);

            GUIContent guiContent = new GUIContent(renderText);

            cursorPosition.y = (rect.yMin + rect.yMax) * 0.5f;           // use center of row to fix issue with incorrect string index between rows
            var renderColumn = LineStyle.GetCursorStringIndex(rect, guiContent, cursorPosition);
            var column       = Whitespace.ConvertToLogicalCaretColumn(renderColumn, Line(row), tabSizes);

            return(new Position(row, column));
        }