Saturday, March 9, 2013

Entire Loaded Program Detection

The only remaining use of edit box ignore change flag mechanism was to stop detection when the document was set using the reimplemented setPlainText() function, which set this ignore flag before calling the base class function and cleared it afterward.  The document change function upon seeing this flag set returned without processing the change.

Since it was now desired to process this change and report all lines as being added, the ignore flag mechanism was removed.  Also, the remaining functionality of the reimplemented setPlainText() function was calling the base class function and then setting the line count variable.  The line count variable will now be set by the document change function, and since this function was only calling the base class function, it was also removed.

For some strange reason, there are actually two document contents change signals generated when the document text is set, one where it indicates one character removed and none added, and a second one with no characters removed and the number of characters in the file added.  My guess is that the first signal is generated from the document being cleared before being set, and the one character is an empty line where the document always contains at least one block (with a single new line).

This first change signal needed to be ignored, which can be accomplished by checking if the document is empty.  However, this is not the only case where the document could be empty (like if all the characters were deleted).  Another indicator was needed for this condition.  The document change function does a move cursor position by the number of characters added to determine where the cursor will end up.  It turns out that this function returns whether the move succeeded.  If the document is empty, this move fails, so this status is captured.  If the document is empty and the move failed, the document change function only resets the modified line and returns.

The cursor position move also fails when with the second signal because the number of characters added is one more than the cursor can be moved.  Since this move fails, the number of lines modified ends up being zero instead of being set to the number of lines in the document that were added.  To emit the correct number of lines inserted, the number of lines changed is only adjusted if the cursor move succeeded or the number of lines modified is not less than the net line count change when lines were added to the document.

[commit 23c1ace139]

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