Ejemplo n.º 1
0
        private void UpdateBlocks()
        {
            if (blocks.Count == 0)
            {
                return;
            }

            // While something is visible after last block...
            while (!blocks.Last().IsLast&& blocks.Last().Position.Y + blockHeight - VerticalOffset < ActualHeight)
            {
                int firstLineIndex = blocks.Last().LineEndIndex + 1;
                int lastLineIndex  = firstLineIndex + maxLineCountInBlock - 1;
                lastLineIndex = lastLineIndex <= totalLineCount - 1 ? lastLineIndex : totalLineCount - 1;

                int fisrCharIndex = blocks.Last().CharEndIndex + 1;
                int lastCharIndex = TextUtilities.GetLastCharIndexFromLineIndex(Text, lastLineIndex);                 // to be optimized (forward search)

                if (lastCharIndex <= fisrCharIndex)
                {
                    blocks.Last().IsLast = true;
                    return;
                }

                InnerTextBlock block = new InnerTextBlock(
                    fisrCharIndex,
                    lastCharIndex,
                    blocks.Last().LineEndIndex + 1,
                    lastLineIndex,
                    LineHeight);
                block.RawText     = block.GetSubString(Text);
                block.LineNumbers = GetFormattedLineNumbers(block.LineStartIndex, block.LineEndIndex);
                blocks.Add(block);
                FormatBlock(block, blocks.Count > 1 ? blocks[blocks.Count - 2] : null);
            }
        }
Ejemplo n.º 2
0
        private void InvalidateBlocks(int changeOffset)
        {
            InnerTextBlock blockChanged = null;

            for (int i = 0; i < blocks.Count; i++)
            {
                if (blocks[i].CharStartIndex <= changeOffset && changeOffset <= blocks[i].CharEndIndex + 1)
                {
                    blockChanged = blocks[i];
                    break;
                }
            }

            if (blockChanged == null && changeOffset > 0)
            {
                blockChanged = blocks.Last();
            }

            int fvline = blockChanged != null ? blockChanged.LineStartIndex : 0;
            int lvline = GetIndexOfLastVisibleLine();
            int fvchar = blockChanged != null ? blockChanged.CharStartIndex : 0;
            int lvchar = TextUtilities.GetLastCharIndexFromLineIndex(Text, lvline);

            if (blockChanged != null)
            {
                blocks.RemoveRange(blocks.IndexOf(blockChanged), blocks.Count - blocks.IndexOf(blockChanged));
            }

            int localLineCount = 1;
            int charStart      = fvchar;
            int lineStart      = fvline;

            for (int i = fvchar; i < Text.Length; i++)
            {
                if (Text[i] == '\n')
                {
                    localLineCount += 1;
                }
                if (i == Text.Length - 1)
                {
                    string         blockText = Text.Substring(charStart);
                    InnerTextBlock block     = new InnerTextBlock(
                        charStart,
                        i, lineStart,
                        lineStart + TextUtilities.GetLineCount(blockText) - 1,
                        LineHeight);
                    block.RawText     = block.GetSubString(Text);
                    block.LineNumbers = GetFormattedLineNumbers(block.LineStartIndex, block.LineEndIndex);
                    block.IsLast      = true;

                    foreach (InnerTextBlock b in blocks)
                    {
                        if (b.LineStartIndex == block.LineStartIndex)
                        {
                            throw new Exception();
                        }
                    }

                    blocks.Add(block);
                    FormatBlock(block, blocks.Count > 1 ? blocks[blocks.Count - 2] : null);
                    break;
                }
                if (localLineCount > maxLineCountInBlock)
                {
                    InnerTextBlock block = new InnerTextBlock(
                        charStart,
                        i,
                        lineStart,
                        lineStart + maxLineCountInBlock - 1,
                        LineHeight);
                    block.RawText     = block.GetSubString(Text);
                    block.LineNumbers = GetFormattedLineNumbers(block.LineStartIndex, block.LineEndIndex);

                    foreach (InnerTextBlock b in blocks)
                    {
                        if (b.LineStartIndex == block.LineStartIndex)
                        {
                            throw new Exception();
                        }
                    }

                    blocks.Add(block);
                    FormatBlock(block, blocks.Count > 1 ? blocks[blocks.Count - 2] : null);

                    charStart      = i + 1;
                    lineStart     += maxLineCountInBlock;
                    localLineCount = 1;

                    if (i > lvchar)
                    {
                        break;
                    }
                }
            }
        }