Beispiel #1
0
        public Selection(MessagePosition start, MessagePosition end)
        {
            if (end.MessageIndex < start.MessageIndex || (end.MessageIndex == start.MessageIndex &&
                                                          (end.WordIndex < start.WordIndex || (end.WordIndex == start.WordIndex &&
                                                                                               (end.SplitIndex < start.SplitIndex || (end.SplitIndex == start.SplitIndex &&
                                                                                                                                      end.CharIndex < start.CharIndex))))))
            {
                First = end;
                Last  = start;
            }
            else
            {
                First = start;
                Last  = end;
            }

            Start = start;
            End   = end;
        }
Beispiel #2
0
        public int IndexFromPosition(MessagePosition pos)
        {
            var isFirstWord = true;

            var index = 0;

            for (var i = 0; i < pos.WordIndex; i++)
            {
                var word = Words[i];

                for (var j = 0; j < (word.SplitSegments?.Length ?? 1); j++)
                {
                    var text = word.SplitSegments?[j].Item1 ?? (string)word.Value;

                    if (j == 0)
                    {
                        if (isFirstWord)
                        {
                            isFirstWord = false;
                        }
                        else
                        {
                            index++;
                        }
                    }

                    for (var k = 0; k < text.Length; k++)
                    {
                        if (pos.WordIndex == i && pos.SplitIndex == j && pos.CharIndex == k)
                        {
                            return(index);
                        }
                    }
                }
            }
            return(0);
        }