[gtk+] Entry: Fix Shift-click → extend/truncate selection



commit 6e414d42d742a6050bd73b870f3dab8b142030df
Author: Daniel Boles <dboles src gmail com>
Date:   Sat Aug 5 23:48:29 2017 +0100

    Entry: Fix Shift-click → extend/truncate selection
    
    Since the move from button-press to gesture events, Shift-clicking did
    not work to start a selection (from none) or truncate an existing one.
    
    This was due to the code being copy-pasted around and some logic being
    broken in the process. This makes both of those work as they should, by
    shuffling it again so the end result is the same as before. Highlights:
    
    (1) ::button-press if extending due to a single press would call
    set_positions(tmp_pos, tmp_pos), which is what made the Shift+click to
    create a selection work. That was lost. Add it back to make that work.
    
    (2) ::button-press in the “Truncate current selection” branch would not
    execute all the stuff around “extend_to_left”, as that was the else
    case. So, set extend_selection = FALSE so we skip over that later on.
    
    (3) BUT! This Truncate case never fired because it was in the else
    branch of if (in_selection())! Of course, it must be in the true branch.
    
    (4) The IM context was not reset if the Shift-click occurred within an
    existing selection, only if it did not. In ::button-press this was the
    first thing done if extending a selection, regardless. Make it so again.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780750

 gtk/gtkentry.c |   37 ++++++++++++++++++++++---------------
 1 files changed, 22 insertions(+), 15 deletions(-)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index e5418f9..a1154a9 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -3698,6 +3698,9 @@ gtk_entry_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
          gtk_widget_get_modifier_mask (widget,
                                        GDK_MODIFIER_INTENT_EXTEND_SELECTION));
 
+      if (extend_selection)
+        gtk_entry_reset_im_context (entry);
+
       switch (n_press)
         {
         case 1:
@@ -3711,15 +3714,24 @@ gtk_entry_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
                   else
                     gtk_entry_selection_bubble_popup_set (entry);
                 }
+              else if (extend_selection)
+                {
+                  /* Truncate current selection, but keep it as big as possible */
+                  if (tmp_pos - sel_start > sel_end - tmp_pos)
+                    gtk_entry_set_positions (entry, sel_start, tmp_pos);
+                  else
+                    gtk_entry_set_positions (entry, tmp_pos, sel_end);
+
+                  /* all done, so skip the extend_to_left stuff later */
+                  extend_selection = FALSE;
+                }
               else
                 {
-                  /* Click inside the selection - we'll either start a drag, or
-                   * clear the selection
-                   */
+                  /* We'll either start a drag, or clear the selection */
                   priv->in_drag = TRUE;
                   priv->drag_start_x = x;
                   priv->drag_start_y = y;
-               }
+                }
             }
           else
             {
@@ -3732,35 +3744,30 @@ gtk_entry_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
                 }
               else
                 {
-                  gtk_entry_reset_im_context (entry);
-
-                  if (!have_selection) /* select from the current position to the clicked position */
+                  /* select from the current position to the clicked position */
+                  if (!have_selection)
                     sel_start = sel_end = priv->current_pos;
 
-                  if (tmp_pos > sel_start && tmp_pos < sel_end)
-                    {
-                      /* Truncate current selection, but keep it as big as possible */
-                      if (tmp_pos - sel_start > sel_end - tmp_pos)
-                        gtk_entry_set_positions (entry, sel_start, tmp_pos);
-                      else
-                        gtk_entry_set_positions (entry, tmp_pos, sel_end);
-                    }
+                  gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
                 }
             }
 
           break;
+
         case 2:
           priv->select_words = TRUE;
           gtk_entry_select_word (entry);
           if (is_touchscreen)
             mode = GTK_TEXT_HANDLE_MODE_SELECTION;
           break;
+
         case 3:
           priv->select_lines = TRUE;
           gtk_entry_select_line (entry);
           if (is_touchscreen)
             mode = GTK_TEXT_HANDLE_MODE_SELECTION;
           break;
+
         default:
           break;
         }


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