[gspell] current word: check current word if deletion not at cursor position



commit 547598730d8001676f3e11477802bcb3529ca18d
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Feb 29 18:04:58 2016 +0100

    current word: check current word if deletion not at cursor position

 gspell/gspell-inline-checker-text-buffer.c  |   23 +++++++++++++++++++----
 testsuite/test-inline-checker-text-buffer.c |   20 ++++++++++++++++----
 2 files changed, 35 insertions(+), 8 deletions(-)
---
diff --git a/gspell/gspell-inline-checker-text-buffer.c b/gspell/gspell-inline-checker-text-buffer.c
index c69dac1..5bae989 100644
--- a/gspell/gspell-inline-checker-text-buffer.c
+++ b/gspell/gspell-inline-checker-text-buffer.c
@@ -521,12 +521,12 @@ delete_range_after_cb (GtkTextBuffer                 *buffer,
        GtkTextIter start_adjusted;
        GtkTextIter end_adjusted;
 
+       g_return_if_fail (gtk_text_iter_equal (start, end));
+
+       /* Adjust iters */
        start_adjusted = *start;
        end_adjusted = *end;
 
-       /* Just to be sure. Normally start == end. */
-       gtk_text_iter_order (&start_adjusted, &end_adjusted);
-
        if (gtk_text_iter_ends_word (&start_adjusted) ||
            (gtk_text_iter_inside_word (&start_adjusted) &&
             !gtk_text_iter_starts_word (&start_adjusted)))
@@ -539,7 +539,22 @@ delete_range_after_cb (GtkTextBuffer                 *buffer,
                gtk_text_iter_forward_word_end (&end_adjusted);
        }
 
-       spell->check_current_word = FALSE;
+       /* Check current word? */
+       if (gtk_text_buffer_get_has_selection (buffer))
+       {
+               spell->check_current_word = TRUE;
+       }
+       else
+       {
+               GtkTextIter cursor_pos;
+
+               gtk_text_buffer_get_iter_at_mark (buffer,
+                                                 &cursor_pos,
+                                                 gtk_text_buffer_get_insert (buffer));
+
+               spell->check_current_word = !gtk_text_iter_equal (start, &cursor_pos);
+       }
+
        add_subregion_to_scan (spell, &start_adjusted, &end_adjusted);
        install_timeout (spell, TIMEOUT_DURATION_BUFFER_MODIFIED);
 }
diff --git a/testsuite/test-inline-checker-text-buffer.c b/testsuite/test-inline-checker-text-buffer.c
index e6234ab..f46dbec 100644
--- a/testsuite/test-inline-checker-text-buffer.c
+++ b/testsuite/test-inline-checker-text-buffer.c
@@ -300,6 +300,8 @@ test_current_word (void)
        GtkTextBuffer *buffer;
        GspellInlineCheckerTextBuffer *inline_checker;
        GtkTextIter iter;
+       GtkTextIter start;
+       GtkTextIter end;
 
        buffer = create_buffer ();
        inline_checker = _gspell_inline_checker_text_buffer_new (buffer);
@@ -332,16 +334,26 @@ test_current_word (void)
 
        /* Cursor movement -> misspelled word highlighted. */
        gtk_text_iter_backward_cursor_position (&iter);
-       gtk_text_buffer_move_mark (buffer,
-                                  gtk_text_buffer_get_insert (buffer),
-                                  &iter);
+       gtk_text_buffer_place_cursor (buffer, &iter);
 
-       /* Buffer content: "Hello nrst". */
+       /* Buffer content: "Hello nrst".
+        * Cursor position: between 's' and 't'.
+        */
        check_highlighted_words (buffer,
                                 inline_checker,
                                 6, 10,
                                 -1);
 
+       /* Delete the 'e' programmatically, not at the cursor position. */
+       gtk_text_buffer_get_iter_at_offset (buffer, &start, 1);
+       gtk_text_buffer_get_iter_at_offset (buffer, &end, 2);
+       gtk_text_buffer_delete (buffer, &start, &end);
+       check_highlighted_words (buffer,
+                                inline_checker,
+                                0, 4,
+                                5, 9, /* "nrst" still highlighted */
+                                -1);
+
        g_object_unref (inline_checker);
        g_object_unref (buffer);
 }


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