From 12d96f27d340ef40a75c6278fbdd9d5a846497de Mon Sep 17 00:00:00 2001 From: Daniel Boles Date: Sat, 5 Aug 2017 23:48:29 +0100 Subject: [PATCH] =?UTF-8?q?Entry:=20Fix=20Shift-click=20=E2=86=92=20extend?= =?UTF-8?q?/truncate=20selection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 file changed, 22 insertions(+), 15 deletions(-) diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 58f1672158..9725eb6dbb 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -4478,6 +4478,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: @@ -4491,15 +4494,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 { @@ -4512,35 +4524,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; }