text: Move setup code out of a loop
authorMatthias Clasen <mclasen@redhat.com>
Thu, 5 Aug 2021 16:29:24 +0000 (12:29 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 5 Aug 2021 16:31:18 +0000 (12:31 -0400)
Just a cleanup, no functional change.

gtk/gtktext.c

index 62f7c90e4c84bc737d5a8fdba3d620c6906bacf6..1cb086dd1f15911637bb9edccc9d4d2a55e23199 100644 (file)
@@ -5049,39 +5049,40 @@ gtk_text_move_visually (GtkText *self,
   int index;
   PangoLayout *layout = gtk_text_ensure_layout (self, FALSE);
   const char *text;
+  gboolean split_cursor;
+  gboolean strong;
 
   text = pango_layout_get_text (layout);
-  
+
   index = g_utf8_offset_to_pointer (text, start) - text;
 
-  while (count != 0)
+
+  g_object_get (gtk_widget_get_settings (GTK_WIDGET (self)),
+                "gtk-split-cursor", &split_cursor,
+                NULL);
+
+  if (split_cursor)
+    strong = TRUE;
+  else
     {
-      int new_index, new_trailing;
-      gboolean split_cursor;
-      gboolean strong;
+      GdkDisplay *display;
+      GdkSeat *seat;
+      GdkDevice *keyboard = NULL;
+      PangoDirection direction = PANGO_DIRECTION_LTR;
 
-      g_object_get (gtk_widget_get_settings (GTK_WIDGET (self)),
-                    "gtk-split-cursor", &split_cursor,
-                    NULL);
+      display = gtk_widget_get_display (GTK_WIDGET (self));
+      seat = gdk_display_get_default_seat (display);
+      if (seat)
+        keyboard = gdk_seat_get_keyboard (seat);
+      if (keyboard)
+        direction = gdk_device_get_direction (keyboard);
 
-      if (split_cursor)
-        strong = TRUE;
-      else
-        {
-          GdkDisplay *display;
-          GdkSeat *seat;
-          GdkDevice *keyboard = NULL;
-          PangoDirection direction = PANGO_DIRECTION_LTR;
-
-          display = gtk_widget_get_display (GTK_WIDGET (self));
-          seat = gdk_display_get_default_seat (display);
-          if (seat)
-            keyboard = gdk_seat_get_keyboard (seat);
-          if (keyboard)
-            direction = gdk_device_get_direction (keyboard);
-
-          strong = direction == priv->resolved_dir;
-        }
+      strong = direction == priv->resolved_dir;
+    }
+
+  while (count != 0)
+    {
+      int new_index, new_trailing;
 
       if (count > 0)
         {
@@ -5098,11 +5099,11 @@ gtk_text_move_visually (GtkText *self,
         index = 0;
       else if (new_index != G_MAXINT)
         index = new_index;
-      
+
       while (new_trailing--)
         index = g_utf8_next_char (text + index) - text;
     }
-  
+
   return g_utf8_pointer_to_offset (text, text + index);
 }