GNOME Bugzilla – Bug 618852
gtk_text_iter_forward_visible_cursor_position does not move to end of buffer/view
Last modified: 2014-07-17 11:01:24 UTC
gtk_text_iter_forward_visible_cursor_position does not move to the last possible cursor position (i.e. the end position), but instead stops before the last character in the buffer.
Created attachment 275320 [details] [review] tests textiter: unit tests for cursor positions See the FIXME comment.
For the fix of this bug I'm waiting for the patches at bug #629129 since they touch the same code.
Review of attachment 275320 [details] [review]: The unit test looks correct to me. Looking forward the patch to actually fix the bug :)
Comment on attachment 275320 [details] [review] tests textiter: unit tests for cursor positions Pushed to the master branch, thanks for the review.
Created attachment 280725 [details] [review] tests textiter: unit tests for visible word boundaries As the FIXME comments show, there are several problems.
Created attachment 280726 [details] [review] tests textiter: unit tests for sentence boundaries As the FIXME comment shows, there is a bug. It is the same bug as for the word boundaries.
Created attachment 280727 [details] [review] textiter: fix bug in find_by_log_attrs() Do not work with the iter passed as the function argument. Work with another iter, and set it back to the function argument only if something has been found. This fixes a few unit tests. But there are regressions for a few others.
Created attachment 280728 [details] [review] textiter: simplify FindLogAttrFunc The min_offset parameter was always 0. Since there are some bugs in this code, it'll be clearer if there are fewer parameters.
Created attachment 280729 [details] [review] textiter: make the FindLogAttrFunc functions clearer - Return true (found) and false (not found) explicitly. - Set found_offset only when something has been found. find_backward_cursor_pos_func() was a bit different, the while loop had the condition "offset > 0" but the return was "offset >= 0". Probably a micro-optimization, since offset == 0 is always a cursor position. Anyway now the code is the same as the other functions.
Created attachment 280730 [details] [review] textiter: fix bug in FindLogAttrFunc functions attrs[len] is the last PangoLogAttr available, at the iter position after the last character of the line. For a line in the middle or the start of the buffer, the '\n' is taken into account by 'len'. For example the is_word_end is generally reached before the '\n', not after. But for the last line in the buffer, where there is no trailing '\n', it is important to test until attrs[len]. The bug didn't occur before because find_by_log_attrs() worked directly on the iter passed as the function argument. But now it is no longer the case.
Created attachment 280746 [details] [review] textiter: fix bug in find_visible_by_log_attrs() find_by_log_attrs() can return true only in this case: return moved && !gtk_text_iter_is_end (arg_iter); So if the iter moved (i.e. something has been found), but is the end iter, find_by_log_attrs() returns false. Now the same checks are made in find_visible_by_log_attrs(). The public functions using find_visible_by_log_attrs() say in their documentation that false is returned for the end iter, hence the check with gtk_text_iter_is_end().
With the last patch this bug is finally fixed.
Review of attachment 280725 [details] [review]: sure
Review of attachment 280726 [details] [review]: ok
Review of attachment 280727 [details] [review]: ok
Review of attachment 280728 [details] [review]: ok
Review of attachment 280729 [details] [review]: ok
Review of attachment 280730 [details] [review]: ok
Review of attachment 280746 [details] [review]: ok
Thanks for the review, all the commits are pushed to the master branch.