[gspell/wip/tune-current-word] inline-checker-text-buffer: get the broader boundaries on insert-text



commit c862d3ddeb9b6a944c7253d2b91641da5fcedf44
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Mar 3 18:07:37 2016 +0100

    inline-checker-text-buffer: get the broader boundaries on insert-text

 gspell/gspell-inline-checker-text-buffer.c |   49 +++++++++++++++++++++++++++-
 1 files changed, 48 insertions(+), 1 deletions(-)
---
diff --git a/gspell/gspell-inline-checker-text-buffer.c b/gspell/gspell-inline-checker-text-buffer.c
index a7d5468..b6ffc14 100644
--- a/gspell/gspell-inline-checker-text-buffer.c
+++ b/gspell/gspell-inline-checker-text-buffer.c
@@ -499,6 +499,47 @@ recheck_all (GspellInlineCheckerTextBuffer *spell)
        check_visible_region (spell);
 }
 
+/* The word boundaries are not necessarily the same before and after a text
+ * insertion or deletion. We need the broader boundaries, so we connect to the
+ * signal without and with the AFTER flag.
+ */
+static void
+insert_text_before_cb (GtkTextBuffer                 *buffer,
+                      GtkTextIter                   *location,
+                      gchar                         *text,
+                      gint                           length,
+                      GspellInlineCheckerTextBuffer *spell)
+{
+       GtkTextIter start;
+       GtkTextIter end;
+
+       start = *location;
+       end = *location;
+
+       /* Adjust iters */
+       if (gtk_text_iter_ends_word (&start) ||
+           (gtk_text_iter_inside_word (&start) &&
+            !gtk_text_iter_starts_word (&start)))
+       {
+               gtk_text_iter_backward_word_start (&start);
+       }
+
+       if (gtk_text_iter_inside_word (&end))
+       {
+               gtk_text_iter_forward_word_end (&end);
+       }
+
+       add_subregion_to_scan (spell, &start, &end);
+
+       /* Don't install_timeout(), it will anyway be called in
+        * insert_text_after_cb(). If install_timeout() is called here, it is a
+        * problem for the unit test mode because the subregion would be scanned
+        * directly, but we need to wait that the text is inserted, otherwise
+        * this can give different results (since the word boundaries are not
+        * necessarily the same).
+        */
+}
+
 static void
 insert_text_after_cb (GtkTextBuffer                 *buffer,
                      GtkTextIter                   *location,
@@ -512,7 +553,7 @@ insert_text_after_cb (GtkTextBuffer                 *buffer,
        start = end = *location;
        gtk_text_iter_backward_chars (&start, g_utf8_strlen (text, length));
 
-       /* Include neighbor words */
+       /* Adjust iters */
        if (gtk_text_iter_ends_word (&start) ||
            (gtk_text_iter_inside_word (&start) &&
             !gtk_text_iter_starts_word (&start)))
@@ -1104,6 +1145,12 @@ set_buffer (GspellInlineCheckerTextBuffer *spell,
 
        g_signal_connect_object (buffer,
                                 "insert-text",
+                                G_CALLBACK (insert_text_before_cb),
+                                spell,
+                                0);
+
+       g_signal_connect_object (buffer,
+                                "insert-text",
                                 G_CALLBACK (insert_text_after_cb),
                                 spell,
                                 G_CONNECT_AFTER);


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