textview: Improve word navigation
authorMatthias Clasen <mclasen@redhat.com>
Sat, 10 Jun 2023 13:03:10 +0000 (09:03 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 10 Jun 2023 13:05:34 +0000 (09:05 -0400)
Both Ctrl-Left and Ctrl-Backspace were failing
to step over a non-word at the beginning of
the line. Fix this to match GtkEntry behavior.

Fixes: #737
gtk/gtktextview.c

index d2ca707b83476504c9f068e9772f87538a5686c4..18aa13c99fa67da263c26087903523443a379d13 100644 (file)
@@ -6477,7 +6477,10 @@ gtk_text_view_move_cursor (GtkTextView     *text_view,
         count *= -1;
 
       if (count < 0)
-        gtk_text_iter_backward_visible_word_starts (&newplace, -count);
+        {
+          if (!gtk_text_iter_backward_visible_word_starts (&newplace, -count))
+            gtk_text_iter_set_line_offset (&newplace, 0);
+        }
       else if (count > 0)
        {
          if (!gtk_text_iter_forward_visible_word_ends (&newplace, count))
@@ -6909,7 +6912,10 @@ gtk_text_view_delete_from_cursor (GtkTextView   *text_view,
       if (count > 0)
         gtk_text_iter_forward_word_ends (&end, count);
       else if (count < 0)
-        gtk_text_iter_backward_word_starts (&start, 0 - count);
+        {
+          if (!gtk_text_iter_backward_word_starts (&start, 0 - count))
+            gtk_text_iter_set_line_offset (&start, 0);
+        }
       break;
 
     case GTK_DELETE_WORDS: