From da8de209284f9bac86c2e4eb80ac921663751d30 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 24 Aug 2012 14:49:58 +0200 Subject: [PATCH] entry: Fix warnings on backwards touch selection from the last position It shouldn't allow backwards selection, but still shouldn't go off bounds trying to keep a minimum selection. --- gtk/gtkentry.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 7116ac8438..cb6e92cb25 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -4338,11 +4338,14 @@ gtk_entry_motion_notify (GtkWidget *widget, { GdkInputSource input_source; GdkDevice *source; + guint length; + + length = gtk_entry_buffer_get_length (get_buffer (entry)); if (event->y < 0) tmp_pos = 0; else if (event->y >= gdk_window_get_height (priv->text_area)) - tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry)); + tmp_pos = length; else tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset); @@ -4389,7 +4392,7 @@ gtk_entry_motion_notify (GtkWidget *widget, * so handles don't get inverted. */ if (input_source == GDK_SOURCE_TOUCHSCREEN) - pos = MAX (gtk_entry_move_backward_word (entry, bound, TRUE), pos); + pos = MIN (MAX (pos, gtk_entry_move_backward_word (entry, bound, TRUE)), length); gtk_entry_set_positions (entry, pos, bound); } @@ -4399,7 +4402,7 @@ gtk_entry_motion_notify (GtkWidget *widget, * so handles don't get inverted. */ if (input_source == GDK_SOURCE_TOUCHSCREEN) - tmp_pos = MAX (priv->selection_bound + 1, tmp_pos); + tmp_pos = MIN (MAX (tmp_pos, priv->selection_bound + 1), length); gtk_entry_set_positions (entry, tmp_pos, -1); }