Esempio n. 1
0
        /// <summary>
        /// Creates a list of segments to split the line into
        /// in order to draw selection boxes
        /// </summary>
        /// <returns></returns>
        protected List <UITextEditLineSegment> CalculateSegments(UITextEditLine line)
        {
            var result = new List <UITextEditLineSegment>();

            if (SelectionEnd != -1)
            {
                /** There is a selection **/
                var start = SelectionStart == -1 ? m_SBuilder.Length : SelectionStart;
                var end   = SelectionEnd == -1 ? m_SBuilder.Length : SelectionEnd;
                if (end < start)
                {
                    var temp = start;
                    start = end;
                    end   = temp;
                }

                var lineStart = line.StartIndex;
                var lineEnd   = lineStart + line.Text.Length;

                /**
                 * Options:
                 *  This line has no selection,
                 *  Selection starts on this line
                 *  Selection ends on this line
                 *  The whole line is selected
                 */

                if (start >= lineStart && start < lineEnd)
                {
                    /** Selection starts on this line, we need a prefix **/
                    var prefixEnd = start - lineStart;
                    if (prefixEnd != 0)
                    {
                        result.Add(new UITextEditLineSegment
                        {
                            Selected = false,
                            Text     = line.Text.Substring(0, prefixEnd)
                        });
                    }

                    /** Up until the end **/
                    var selectionEnd = line.Text.Length;
                    if (end + 1 < lineEnd)
                    {
                        selectionEnd -= (lineEnd - end);
                    }

                    result.Add(new UITextEditLineSegment
                    {
                        Selected = true,
                        Text     = line.Text.Substring(prefixEnd, selectionEnd - prefixEnd)
                    });

                    /** Suffix? **/
                    if (end + 1 < lineEnd)
                    {
                        result.Add(new UITextEditLineSegment
                        {
                            Selected = false,
                            Text     = line.Text.Substring(selectionEnd)
                        });
                    }
                }
                else if (start < lineStart && end >= lineStart && end <= lineEnd)
                {
                    /** Selection ends on this line **/
                    /** Up until the end **/
                    var selectionEnd = line.Text.Length;
                    if (end + 1 < lineEnd)
                    {
                        selectionEnd -= (lineEnd - end);
                    }

                    result.Add(new UITextEditLineSegment
                    {
                        Selected = true,
                        Text     = line.Text.Substring(0, selectionEnd)
                    });

                    /** Suffix? **/
                    if (end + 1 < lineEnd)
                    {
                        result.Add(new UITextEditLineSegment
                        {
                            Selected = false,
                            Text     = line.Text.Substring(selectionEnd)
                        });
                    }
                }
                else if (start < lineStart && end > lineEnd)
                {
                    /** The whole line is selected **/
                    result.Add(new UITextEditLineSegment
                    {
                        Text     = line.Text,
                        Selected = true
                    });
                }
                else
                {
                    result.Add(new UITextEditLineSegment
                    {
                        Text     = line.Text,
                        Selected = false
                    });
                }

                //if (lineStart >= start && lineEnd <= end)
                //{
                //    /** Part of this line is selected **/
                //    result.Add(new UITextEditLineSegment
                //    {
                //        Selected = true,
                //        Text = line.Text
                //    });
                //}
            }
            else
            {
                result.Add(new UITextEditLineSegment
                {
                    Text     = line.Text,
                    Selected = false
                });
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a list of segments to split the line into
        /// in order to draw selection boxes
        /// </summary>
        /// <returns></returns>
        protected List<UITextEditLineSegment> CalculateSegments(UITextEditLine line)
        {
            var result = new List<UITextEditLineSegment>();

            if (SelectionEnd != -1)
            {
                /** There is a selection **/
                var start = SelectionStart == -1 ? m_SBuilder.Length : SelectionStart;
                var end = SelectionEnd == -1 ? m_SBuilder.Length : SelectionEnd;
                if (end < start)
                {
                    var temp = start;
                    start = end;
                    end = temp;
                }

                var lineStart = line.StartIndex;
                var lineEnd = lineStart + line.Text.Length;

                /**
                 * Options:
                 *  This line has no selection,
                 *  Selection starts on this line
                 *  Selection ends on this line
                 *  The whole line is selected
                 */

                if (start >= lineStart && start < lineEnd)
                {
                    /** Selection starts on this line, we need a prefix **/
                    var prefixEnd = start - lineStart;
                    if (prefixEnd != 0)
                    {
                        result.Add(new UITextEditLineSegment
                        {
                            Selected = false,
                            Text = line.Text.Substring(0, prefixEnd)
                        });
                    }

                    /** Up until the end **/
                    var selectionEnd = line.Text.Length;
                    if (end + 1 < lineEnd)
                    {
                        selectionEnd -= (lineEnd - end);
                    }

                    result.Add(new UITextEditLineSegment
                    {
                        Selected = true,
                        Text = line.Text.Substring(prefixEnd, selectionEnd - prefixEnd)
                    });

                    /** Suffix? **/
                    if (end + 1 < lineEnd)
                    {
                        result.Add(new UITextEditLineSegment
                        {
                            Selected = false,
                            Text = line.Text.Substring(selectionEnd)
                        });
                    }
                }
                else if (start < lineStart && end >= lineStart && end <= lineEnd)
                {
                    /** Selection ends on this line **/
                    /** Up until the end **/
                    var selectionEnd = line.Text.Length;
                    if (end + 1 < lineEnd)
                    {
                        selectionEnd -= (lineEnd - end);
                    }

                    result.Add(new UITextEditLineSegment
                    {
                        Selected = true,
                        Text = line.Text.Substring(0, selectionEnd)
                    });

                    /** Suffix? **/
                    if (end + 1 < lineEnd)
                    {
                        result.Add(new UITextEditLineSegment
                        {
                            Selected = false,
                            Text = line.Text.Substring(selectionEnd)
                        });
                    }
                }
                else if (start < lineStart && end > lineEnd)
                {
                    /** The whole line is selected **/
                    result.Add(new UITextEditLineSegment
                    {
                        Text = line.Text,
                        Selected = true
                    });
                }
                else
                {
                    result.Add(new UITextEditLineSegment
                    {
                        Text = line.Text,
                        Selected = false
                    });
                }
            }
            else
            {
                result.Add(new UITextEditLineSegment
                {
                    Text = line.Text,
                    Selected = false
                });
            }
            return result;
        }