Saturday, March 9, 2013

Newly Inserted Lines Fix

When a new program is loaded, the entire program must be loaded into the document (as plain text) and the class that will hold the encoded program.  One method would be to set the edit box document to the plain text of the program and then set the program class.  Another method is to allow the program change signal that would be emitted when the document is set to the text of the program (which is presently disabled).

After re-enabling the signal when the document text is set, and trying to get the proper signals to be emitted, I discovered that newly inserted lines were not always being emitted correctly.  A simple example of this is when a return is entered at the end of the new line - the line was reported as changed instead of inserted.

This problem occurred because the code needed to check if the current modified line is going to be new, but was not previously new before adjusting the number of lines changed and inserted for the new line.  When the line is new, but wasn't previously new, the number of lines modified is incremented by one and the number of inserted lines is decremented by one to account for the new line that hasn't been inserted yet.

The aid in debugging, a status indicator character was added to the line number widget after the line number of the current line to indicate when the current line is modified (with an asterisk) or is new (with a plus).  This is easier than having a message on the console indicating the line number modified and new status, and then having to refer to edit box to see which line the cursor is at.

[commit 9f15211791]

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.)