Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 8698272

Browse files
committed
When replacing the whole document, ensure the deleted lines have IsDeleted set to true.
1 parent ed42398 commit 8698272

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/LineManagerTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
using System;
2020
using System.Collections.Generic;
21+
using System.Linq;
2122
using NUnit.Framework;
2223

2324
namespace ICSharpCode.AvalonEdit.Document
@@ -46,10 +47,16 @@ public void CheckClearingDocument()
4647
{
4748
document.Text = "Hello,\nWorld!";
4849
Assert.AreEqual(2, document.LineCount);
50+
var oldLines = document.Lines.ToArray();
4951
document.Text = "";
5052
Assert.AreEqual("", document.Text);
5153
Assert.AreEqual(0, document.TextLength);
5254
Assert.AreEqual(1, document.LineCount);
55+
Assert.AreSame(oldLines[0], document.Lines.Single());
56+
Assert.IsFalse(oldLines[0].IsDeleted);
57+
Assert.IsTrue(oldLines[1].IsDeleted);
58+
Assert.IsNull(oldLines[0].NextLine);
59+
Assert.IsNull(oldLines[1].PreviousLine);
5360
}
5461

5562
[Test]

src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/LineManager.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ public void Rebuild()
105105
{
106106
// keep the first document line
107107
DocumentLine ls = documentLineTree.GetByNumber(1);
108+
// but mark all other lines as deleted, and detach them from the other nodes
109+
for (DocumentLine line = ls.NextLine; line != null; line = line.NextLine) {
110+
line.isDeleted = true;
111+
line.parent = line.left = line.right = null;
112+
}
113+
// Reset the first line to detach it from the deleted lines
114+
ls.ResetLine();
108115
SimpleSegment ds = NewLineFinder.NextNewLine(document, 0);
109116
List<DocumentLine> lines = new List<DocumentLine>();
110117
int lastDelimiterEnd = 0;
@@ -117,7 +124,6 @@ public void Rebuild()
117124
ls = new DocumentLine(document);
118125
ds = NewLineFinder.NextNewLine(document, lastDelimiterEnd);
119126
}
120-
ls.ResetLine();
121127
ls.TotalLength = document.TextLength - lastDelimiterEnd;
122128
lines.Add(ls);
123129
documentLineTree.RebuildTree(lines);

0 commit comments

Comments
 (0)