Esempio n. 1
0
        public Pos WWPosOfIndex(int index)
        {
            CutOff cutOff = new CutOff(0, 0, 0);
            int    iy     = 0;

            for (; iy < cutOffs.count && cutOffs.buffer[iy].iChar <= index; iy++)
            {
                cutOff = cutOffs.buffer[iy];
            }
            int pos = 0;

            for (int i = cutOff.iChar; i < index; ++i)
            {
                if (chars[i].c == '\t')
                {
                    pos = ((pos + tabSize) / tabSize) * tabSize;
                }
                else
                {
                    pos++;
                }
            }
            pos += cutOff.left;
            return(new Pos(pos, iy));
        }
Esempio n. 2
0
        public int WWIndexOfPos(int pos, int iSubline)
        {
            if (iSubline > cutOffs.count)
            {
                return(charsCount);
            }

            CutOff cutOff;

            if (iSubline <= 0)
            {
                cutOff = new CutOff(0, 0, 0);
            }
            else
            {
                cutOff = cutOffs.buffer[iSubline - 1];
            }

            int count = iSubline < cutOffs.count ? cutOffs.buffer[iSubline].iChar - 1 : charsCount;
            int iPos  = cutOff.left;

            for (int i = cutOff.iChar; i < count; ++i)
            {
                if (chars[i].c == '\t')
                {
                    int prevPos = iPos;
                    iPos = ((iPos + tabSize) / tabSize) * tabSize;
                    if (iPos > pos)
                    {
                        return(i + (2 * (pos - prevPos) - 1) / (iPos - prevPos));
                    }
                }
                else
                {
                    iPos++;
                    if (iPos > pos)
                    {
                        return(i);
                    }
                }
            }
            return(count);
        }
Esempio n. 3
0
        public void CalcCutOffs(int wwSizeX)
        {
            this.wwSizeX = wwSizeX;
            cutOffs.Clear();
            int count = charsCount;

            if (count > 4)
            {
                int  i;
                int  left              = GetFirstSpaceSize(out i);
                int  pos               = left;
                int  lastSeparator     = 0;
                int  prevLastSeparator = 0;
                int  lastPos           = 0;
                char prev              = '\0';
                while (i < count)
                {
                    char c = chars[i].c;
                    if (!char.IsWhiteSpace(c) && (char.IsWhiteSpace(prev) || !char.IsLetterOrDigit(c)))
                    {
                        prevLastSeparator = lastSeparator;
                        lastSeparator     = i;
                        lastPos           = pos;
                    }
                    if (pos >= wwSizeX)
                    {
                        if (lastSeparator > prevLastSeparator)
                        {
                            i = lastSeparator;
                        }
                        else
                        {
                            if (left > 0 && cutOffs.count > 0)
                            {
                                int    index      = cutOffs.count - 1;
                                CutOff prevCutOff = cutOffs.buffer[index];
                                cutOffs.buffer[index] = new CutOff(prevCutOff.iChar, 0, prevCutOff.sizeX);
                                pos -= left;
                                left = 0;

                                prev = c;
                                pos  = c == '\t' ? ((pos + tabSize) / tabSize) * tabSize : pos + 1;
                                ++i;
                                continue;
                            }
                            else
                            {
                                lastSeparator = i;
                                lastPos       = pos;
                            }
                        }
                        cutOffs.Add(new CutOff(lastSeparator, left, lastPos));
                        pos = left;
                        prevLastSeparator = lastSeparator;
                        prev = '\0';
                    }
                    else
                    {
                        prev = c;
                        pos  = c == '\t' ? ((pos + tabSize) / tabSize) * tabSize : pos + 1;
                        ++i;
                    }
                }
                lastSublineSizeX = pos;
            }
            else
            {
                lastSublineSizeX = Size;
            }
        }
Esempio n. 4
0
 private string StringOfCutOff(MulticaretEditor.CutOff cutOff)
 {
     return(cutOff + ":" + cutOff.sizeX);
 }