[gedit/wip/spell-checking: 2/2] auto-spell: remove insert_text_before_cb()



commit 376632b33cc937cbb41353dfac5c26a25efc2357
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Jul 20 11:16:17 2015 +0200

    auto-spell: remove insert_text_before_cb()
    
    insert_text_after_cb() is sufficient, we can compute the start iter with
    the text and length parameters.

 plugins/spell/gedit-automatic-spell-checker.c |   45 +++++--------------------
 1 files changed, 9 insertions(+), 36 deletions(-)
---
diff --git a/plugins/spell/gedit-automatic-spell-checker.c b/plugins/spell/gedit-automatic-spell-checker.c
index 622eafa..08af6b1 100644
--- a/plugins/spell/gedit-automatic-spell-checker.c
+++ b/plugins/spell/gedit-automatic-spell-checker.c
@@ -212,46 +212,25 @@ check_deferred_range (GeditAutomaticSpellChecker *spell,
        check_range (spell, &start, &end, force_all);
 }
 
-/* insertion works like this:
- *  - before the text is inserted, we mark the position in the buffer.
- *  - after the text is inserted, we see where our mark is and use that and
- *    the current position to check the entire range of inserted text.
- *
- * this may be overkill for the common case (inserting one character). */
-
-static void
-insert_text_before_cb (GtkTextBuffer              *buffer,
-                      GtkTextIter                *iter,
-                      gchar                      *text,
-                      gint                        len,
-                      GeditAutomaticSpellChecker *spell)
-{
-       gtk_text_buffer_move_mark (buffer, spell->mark_insert_start, iter);
-}
-
 static void
 insert_text_after_cb (GtkTextBuffer              *buffer,
-                     GtkTextIter                *iter,
+                     GtkTextIter                *location,
                      gchar                      *text,
-                     gint                        len,
+                     gint                        length,
                      GeditAutomaticSpellChecker *spell)
 {
        GtkTextIter start;
+       GtkTextIter end;
 
-       /* we need to check a range of text. */
-       gtk_text_buffer_get_iter_at_mark (buffer, &start, spell->mark_insert_start);
+       start = end = *location;
 
-       check_range (spell, &start, iter, FALSE);
+       gtk_text_iter_backward_chars (&start, g_utf8_strlen (text, length));
 
-       gtk_text_buffer_move_mark (buffer, spell->mark_insert_end, iter);
-}
+       gtk_text_buffer_move_mark (buffer, spell->mark_insert_start, &start);
+       gtk_text_buffer_move_mark (buffer, spell->mark_insert_end, &end);
 
-/* deleting is more simple:  we're given the range of deleted text.
- * after deletion, the start and end iters should be at the same position
- * (because all of the text between them was deleted!).
- * this means we only really check the words immediately bounding the
- * deletion.
- */
+       check_range (spell, &start, &end, FALSE);
+}
 
 static void
 delete_range_after_cb (GtkTextBuffer              *buffer,
@@ -703,12 +682,6 @@ set_buffer (GeditAutomaticSpellChecker *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]