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
This commit is contained in:
Daniel Boles 2017-08-05 23:48:29 +01:00 committed by Daniel Boles
parent 81d6f8d81c
commit 12d96f27d3

View File

@ -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;
}