[gtk+] GtkLabel: better treatment for selection with ellipsis



commit 1cc5cf3797b36500bd1e7b3e316161a5dc7df7b5
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Sep 3 22:18:49 2014 -0400

    GtkLabel: better treatment for selection with ellipsis
    
    This commit arranges things so that we treat an ellipsized
    region like a single character for the purpose of selection
    and cursor navigation.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=328449

 gtk/gtklabel.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 9c9d098..3f549a0 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -5578,6 +5578,60 @@ gtk_label_select_region_index (GtkLabel *label,
   if (priv->select_info && priv->select_info->selectable)
     {
       GtkClipboard *clipboard;
+      gint s, e;
+
+      /* Ensure that we treat an ellipsized region like a single
+       * character with respect to selection.
+       */
+      if (anchor_index < end_index)
+        {
+          if (range_is_in_ellipsis_full (label, anchor_index, anchor_index + 1, &s, &e))
+            {
+              if (priv->select_info->selection_anchor == s)
+                anchor_index = e;
+              else
+                anchor_index = s;
+            }
+          if (range_is_in_ellipsis_full (label, end_index - 1, end_index, &s, &e))
+            {
+              if (priv->select_info->selection_end == e)
+                end_index = s;
+              else
+                end_index = e;
+            }
+        }
+      else if (end_index < anchor_index)
+        {
+          if (range_is_in_ellipsis_full (label, end_index, end_index + 1, &s, &e))
+            {
+              if (priv->select_info->selection_end == s)
+                end_index = e;
+              else
+                end_index = s;
+            }
+          if (range_is_in_ellipsis_full (label, anchor_index - 1, anchor_index, &s, &e))
+            {
+              if (priv->select_info->selection_anchor == e)
+                anchor_index = s;
+              else
+                anchor_index = e;
+            }
+        }
+      else
+        {
+          if (range_is_in_ellipsis_full (label, anchor_index, anchor_index, &s, &e))
+            {
+              if (priv->select_info->selection_anchor == s)
+                anchor_index = e;
+              else if (priv->select_info->selection_anchor == e)
+                anchor_index = s;
+              else if (anchor_index - s < e - anchor_index)
+                anchor_index = s;
+              else
+                anchor_index = e;
+              end_index = anchor_index;
+            }
+        }
 
       if (priv->select_info->selection_anchor == anchor_index &&
           priv->select_info->selection_end == end_index)


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