Building a large text file editor – Part II

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:

 

LFETester.zip

Comments

  • Anonymous
    September 29, 2016
    Thank you, Costin, for the post and explanations. Looks really fast and clean. Though, it can handle only existing files and failes when user enters data directly in the textbox without opening any file (keying in or copy/paste). Do you have an update for this solution? I'm trying to find a good way for editing huge files (64Mb) with minimum formatting in my WPF MVVM project and would appreciate any help. Valentina