[evolution] EBufferTagger::markup_text: User character offset when tagging links



commit 383155344a2c05eb103f939d81dc264c68657690
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jul 27 11:10:16 2015 +0200

    EBufferTagger::markup_text: User character offset when tagging links
    
    The regexec() match result returns byte offset, while gtk_text_buffer_get_iter_at_offset()
    expects character offset, thus when the text contains any UTF-8 letters before the found URL
    the link position was shifted by the UTF-8 bytes.

 e-util/e-buffer-tagger.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/e-util/e-buffer-tagger.c b/e-util/e-buffer-tagger.c
index c3c923a..91c9ea8 100644
--- a/e-util/e-buffer-tagger.c
+++ b/e-util/e-buffer-tagger.c
@@ -109,13 +109,18 @@ markup_text (GtkTextBuffer *buffer)
                any = FALSE;
                for (i = 0; i < G_N_ELEMENTS (mim); i++) {
                        if (mim[i].preg && !regexec (mim[i].preg, str, 2, pmatch, 0)) {
-                               gtk_text_buffer_get_iter_at_offset (buffer, &start, offset + pmatch[0].rm_so);
-                               gtk_text_buffer_get_iter_at_offset (buffer, &end, offset + pmatch[0].rm_eo);
+                               gint char_so, char_eo;
+
+                               char_so = g_utf8_pointer_to_offset (str, str + pmatch[0].rm_so);
+                               char_eo = g_utf8_pointer_to_offset (str, str + pmatch[0].rm_eo);
+
+                               gtk_text_buffer_get_iter_at_offset (buffer, &start, offset + char_so);
+                               gtk_text_buffer_get_iter_at_offset (buffer, &end, offset + char_eo);
                                gtk_text_buffer_apply_tag_by_name (buffer, E_BUFFER_TAGGER_LINK_TAG, &start, 
&end);
 
                                any = TRUE;
                                str += pmatch[0].rm_eo;
-                               offset += pmatch[0].rm_eo;
+                               offset += char_eo;
                                break;
                        }
                }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]