In the previous post I created a class that was going to be used as an interface between a large file editor and the file on the disk.

Since then I've been implementing the user interface and, obviously, the RevisionStream also needed some readjustment. Here are some major changes that were done:

- detecting encoding of text file

- support for Unicode (2-bytes characters)

- some bugs related to addition and deletion

 

Until now I've managed to repair most of the visible bugs but I'm pretty sure there are some also remaining. Which is why, apart from the UserControl that holds the large file editor, I've also created a Form for testing the control. The source code is available so everyone interested and go ahead and fix the bugs they discover. I will also appreciate if you post comments with feedback.

The UserControl LargeTextBox contains a RichTextBox and a vertical scroll bar.

 

Apart from the RevisionStream, the LargeTextBox control also contains:

 -  long topPosition; // The position in the changed stream of first line in RTB

 - char[][] displayedLines; // The list of currently displayed text lines

 - int[] lineLengths; // The list of lengths of currently displayed text lines     

The most delicate part of the whole process is to detect the changes done by the user in the RichTextBox and update them in the Revision Stream. This is implemented in the method SynchDifferences where the cached lines are compared with the lines from the RichTextBox and Insertions and Deletions are added accordingly.

Let's see how this works on an Excel file. I create a Workbook with as many rows as Excel allows, namely 1,048,576. I saved this to Book2.xlsx and extracted the sheet1.xml. I then indented the XML to make more human-readable and loded it into the editor.

 

I then scrolled down to row 511,386 and added a new cell on the B column with the value of "0".


 

I saved the XML as sheet2.xml and then renamed it back to sheet1.xml (minor bug remaining - can't save to same file name). After repackaging the file in Excel, here's the result: