diff options
author | Sébastien Wilmet <swilmet@gnome.org> | 2015-11-26 13:31:19 +0100 |
---|---|---|
committer | Sébastien Wilmet <swilmet@gnome.org> | 2015-11-30 19:46:16 +0100 |
commit | 1a8f3e2462829f8a186590a6ad6b7642309baa5b (patch) | |
tree | 7fb64ae5d767b38adad0c4cda2e03c819e29d4e2 /gtk/gtktextiter.c | |
parent | 0a35886b0a39a57b819d1f51adb357c13bda5bf3 (diff) | |
download | gtk+-1a8f3e2462829f8a186590a6ad6b7642309baa5b.tar.gz |
textiter: fix bug in case insensitive backward search
'win.lines' contains the same content as the GtkTextBuffer, so to find
@match_start, forward_chars_with_skipping() is called with
skip_decomp=FALSE (the last parameter). So far so good.
On the other hand, the content 'lines' (the needle split in lines) is
casefolded and normalized for a case insensitive search. So,
forward_chars_with_skipping(..., skip_decomp=TRUE) must be called only
for the portion of text containing the needle.
Since 'start_tmp' contains the location at the start of the match, we
can simply begin at that location to find the end of the match.
Unit tests are added.
https://bugzilla.gnome.org/show_bug.cgi?id=758698
Diffstat (limited to 'gtk/gtktextiter.c')
-rw-r--r-- | gtk/gtktextiter.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/gtk/gtktextiter.c b/gtk/gtktextiter.c index a863c38682..2496ea85bc 100644 --- a/gtk/gtktextiter.c +++ b/gtk/gtktextiter.c @@ -5309,37 +5309,34 @@ gtk_text_iter_backward_search (const GtkTextIter *iter, { /* Match! */ gint offset; - GtkTextIter next; GtkTextIter start_tmp; - + GtkTextIter end_tmp; + /* Offset to start of search string */ offset = g_utf8_strlen (*win.lines, first_line_match - *win.lines); - next = win.first_line_start; - start_tmp = next; + start_tmp = win.first_line_start; forward_chars_with_skipping (&start_tmp, offset, visible_only, !slice, FALSE); if (limit && gtk_text_iter_compare (limit, &start_tmp) > 0) goto out; /* match was bogus */ - + if (match_start) *match_start = start_tmp; /* Go to end of search string */ - l = lines; - while (*l) - { - offset += g_utf8_strlen (*l, -1); - ++l; - } + offset = 0; + for (l = lines; *l != NULL; l++) + offset += g_utf8_strlen (*l, -1); - forward_chars_with_skipping (&next, offset, + end_tmp = start_tmp; + forward_chars_with_skipping (&end_tmp, offset, visible_only, !slice, case_insensitive); if (match_end) - *match_end = next; + *match_end = end_tmp; retval = TRUE; goto out; |