Example #1
0
        void RemoveInternal(ref DeferredEventList deferredEventList, int offset, int length)
        {
            Debug.Assert(length >= 0);
            if (length == 0)
            {
                return;
            }
            LineSegmentTree.Enumerator it  = lineCollection.GetEnumeratorForOffset(offset);
            LineSegment startSegment       = it.Current;
            int         startSegmentOffset = startSegment.Offset;

            if (offset + length < startSegmentOffset + startSegment.TotalLength)
            {
                // just removing a part of this line segment
                startSegment.RemovedLinePart(ref deferredEventList, offset - startSegmentOffset, length);
                SetSegmentLength(startSegment, startSegment.TotalLength - length);
                return;
            }
            // merge startSegment with another line segment because startSegment's delimiter was deleted
            // possibly remove lines in between if multiple delimiters were deleted
            int charactersRemovedInStartLine = startSegmentOffset + startSegment.TotalLength - offset;

            Debug.Assert(charactersRemovedInStartLine > 0);
            startSegment.RemovedLinePart(ref deferredEventList, offset - startSegmentOffset, charactersRemovedInStartLine);


            LineSegment endSegment = lineCollection.GetByOffset(offset + length);

            if (endSegment == startSegment)
            {
                // special case: we are removing a part of the last line up to the
                // end of the document
                SetSegmentLength(startSegment, startSegment.TotalLength - length);
                return;
            }
            int endSegmentOffset        = endSegment.Offset;
            int charactersLeftInEndLine = endSegmentOffset + endSegment.TotalLength - (offset + length);

            endSegment.RemovedLinePart(ref deferredEventList, 0, endSegment.TotalLength - charactersLeftInEndLine);
            startSegment.MergedWith(endSegment, offset - startSegmentOffset);
            SetSegmentLength(startSegment, startSegment.TotalLength - charactersRemovedInStartLine + charactersLeftInEndLine);
            startSegment.DelimiterLength = endSegment.DelimiterLength;
            // remove all segments between startSegment (excl.) and endSegment (incl.)
            it.MoveNext();
            LineSegment segmentToRemove;

            do
            {
                segmentToRemove = it.Current;
                it.MoveNext();
                lineCollection.RemoveSegment(segmentToRemove);
                segmentToRemove.Deleted(ref deferredEventList);
            } while (segmentToRemove != endSegment);
        }
Example #2
0
 /// <summary>
 /// Is called when the LineSegment is deleted.
 /// </summary>
 internal void Deleted(ref DeferredEventList deferredEventList)
 {
     //Console.WriteLine("Deleted");
     treeEntry = LineSegmentTree.Enumerator.Invalid;
     if (anchors != null)
     {
         foreach (TextAnchor a in anchors)
         {
             a.Delete(ref deferredEventList);
         }
         anchors = null;
     }
 }
Example #3
0
 void RunHighlighter(int firstLine, int lineCount)
 {
     if (highlightingStrategy != null)
     {
         List <LineSegment>         markLines = new List <LineSegment>();
         LineSegmentTree.Enumerator it        = lineCollection.GetEnumeratorForIndex(firstLine);
         for (int i = 0; i < lineCount && it.IsValid; i++)
         {
             markLines.Add(it.Current);
             it.MoveNext();
         }
         highlightingStrategy.MarkTokens(document, markLines);
     }
 }