Sunday, March 3, 2013

New Line Change Detection Code

Detecting all line changes can be performed by connecting to the edit box document's contents change signal that includes the position in the document of the change along with the number of characters removed and added.  Previously, only the number of character values were being saved for the various detection routines and the position was ignored.  However, the position can be used along with some additional information, to fully detect what has changed in the document, and it turns out the number of characters values no longer need to be stored.

One piece of additional information needed is the net change in the number of lines of the document, which can be used to indicate whether lines were inserted or deleted.  Therefore, a new total line count variable was added to the edit box class and updated after processing a contents change signal.  Other information used is if the position of the change was at the beginning of the line and if the cursor is at the end of the line after the change.

The three signals emitted from the edit box for program changes (line changed, lines inserted and lines deleted) were replaced with a single lines changed signal that includes the line number of the change, the number of lines deleted (could be zero), the number of lines inserted (could be zero) and a list of strings of the lines that were changed (if any) and inserted (if any).  The number of lines changed is the size of this list minus the number of lines inserted.

One of the things the new detection code does not do that the old code attempted to do was determine whether a line actually changed or not, and if not it is not reported.  For example, inserted text that started with a new line inserted at the end of a line, the line is not actually modified so it wasn't reported.  Since the new code does not do this, the receiver of the lines changed signal, will perform this check to see if a particular line was actually changed (to prevent the line from being recompiled).

The new line change detection code is mostly fully working, however, it is not completely hooked up to all the possible document changes that can occur.  In some cases, the code was simply modified to compile, so some code was temporarily commented instead of being changed.  In other cases, the code was modified like the capture deleted lines routine was not needed and was removed.  All of the other causes of changes will be hooked and the code will be cleaned up over the next set of commits.

[commit 00dfbe3268]

No comments:

Post a Comment

All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)