public void AddRepeated()
 {
     CompressingTreeList<int> list = new CompressingTreeList<int>((a, b) => a == b);
     list.Add(42);
     list.Add(42);
     list.Add(42);
     list.Insert(0, 42);
     list.Insert(1, 42);
     Assert.AreEqual(new[] { 42, 42, 42, 42, 42 }, list.ToArray());
 }
        public void AddRepeated()
        {
            CompressingTreeList <int> list = new CompressingTreeList <int>((a, b) => a == b);

            list.Add(42);
            list.Add(42);
            list.Add(42);
            list.Insert(0, 42);
            list.Insert(1, 42);
            Assert.AreEqual(new[] { 42, 42, 42, 42, 42 }, list.ToArray());
        }
Exemple #3
0
 /// <summary>
 /// Invalidates all stored highlighting info.
 /// When the document changes, the highlighting is invalidated automatically, this method
 /// needs to be called only when there are changes to the highlighting rule set.
 /// </summary>
 public void InvalidateHighlighting()
 {
     storedSpanStacks.Clear();
     storedSpanStacks.Add(SpanStack.Empty);
     storedSpanStacks.InsertRange(1, document.LineCount, null);
     isValid.Clear();
     isValid.Add(true);
     isValid.InsertRange(1, document.LineCount, false);
     firstInvalidLine = 1;
 }
 /// <summary>
 /// Invalidates stored highlighting info, but does not raise the HighlightingStateChanged event.
 /// </summary>
 void InvalidateSpanStacks()
 {
     CheckIsHighlighting();
     storedSpanStacks.Clear();
     storedSpanStacks.Add(initialSpanStack);
     storedSpanStacks.InsertRange(1, document.LineCount, null);
     isValid.Clear();
     isValid.Add(true);
     isValid.InsertRange(1, document.LineCount, false);
     firstInvalidLine = 1;
 }
        void SetupInitialFileState(bool update)
        {
            if (baseDocument == null)
            {
                if (update)
                {
                    changeList.Transform(TransformLineChangeInfo);
                }
                else
                {
                    changeList.InsertRange(0, document.TotalNumberOfLines + 1, LineChangeInfo.Empty);
                }
            }
            else
            {
                changeList.Clear();

                Dictionary <string, int> hashes = new Dictionary <string, int>();

                MyersDiff.MyersDiff diff = new MyersDiff.MyersDiff(
                    new DocumentSequence(baseDocument, hashes),
                    new DocumentSequence(document, hashes)
                    );

                changeList.Add(LineChangeInfo.Empty);
                int lastEndLine = 0;

                foreach (Edit edit in diff.GetEdits())
                {
                    int beginLine = edit.BeginB;
                    int endLine   = edit.EndB;

                    changeList.InsertRange(changeList.Count, beginLine - lastEndLine, LineChangeInfo.Empty);

                    LineChangeInfo change = new LineChangeInfo(edit.EditType, edit.BeginA, edit.BeginB, edit.EndA, edit.EndB);
                    if (endLine == beginLine)
                    {
                        changeList[changeList.Count - 1] = change;
                    }
                    else
                    {
                        changeList.InsertRange(changeList.Count, endLine - beginLine, change);
                    }

                    lastEndLine = endLine;
                }

                changeList.InsertRange(changeList.Count, textDocument.LineCount - lastEndLine, LineChangeInfo.Empty);
            }

            OnChangeOccurred(EventArgs.Empty);
        }