Sunday, January 5, 2014

Edit Box – Line Wrapping Problem

While working on the next set of changes, an unrelated problem was discovered with error highlighting.  The problem occurred when there were long lines that wrapped onto the next line.  The problem was first noticed when a line with an error was modified and error was shifted to the wrong place.  The problem also occurred in other situations, including moving to an error that was in the wrapped portion of a line, or when a recreated line was after a wrapped line.

The problem was identified to be the use of the findBlockByLineNumber() function, a member of the QTextDocument class that holds the document of the edit box (in the QPlainTextEdit base class).  This function was being used to get the text block for a given line number, which was then used to gets its position within the document to set the position of the cursor.

However, this function was not working as expected.  What it actually does is return the text block of the actual physical line specified, which takes into account wrapped lines where each part of a wrapped line counts as separate lines.  The findBlockByNumber() function does work as needed and does not consider wrapped lines.  This latter function was already being used in two places, but not in three others.

On the surface, these two functions appear to do the same thing for a plain text document.  The only difference in the help documentation was in the argument, one taking a line number and the other taking a block number.  It was incorrectly assumed that line number meant the same thing as block number.  It is true that each line is a block in a plain text document, but a line number actually represents the physical line on the screen.  Once the latter function was used throughout, there were no problems.

[commit bf7fb54a79]

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