This repository was archived by the owner on Oct 16, 2020. It is now read-only.
File tree Expand file tree Collapse file tree
ICSharpCode.AvalonEdit.Tests/Document
ICSharpCode.AvalonEdit/Document Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818
1919using System ;
2020using System . Collections . Generic ;
21+ using System . Linq ;
2122using NUnit . Framework ;
2223
2324namespace ICSharpCode . AvalonEdit . Document
@@ -46,10 +47,16 @@ public void CheckClearingDocument()
4647 {
4748 document . Text = "Hello,\n World!" ;
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 ]
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments