GNOME Bugzilla – Bug 50940
GtkEntry selection improvement [patch]
Last modified: 2017-08-19 15:02:48 UTC
It should be possible to click and drag upwords to select the begining portion of a gtkentry and also to click and drag downwards to select the end portion of the entry. This behaviour is standard on macOS. If this version seems a bit too touchy when not trying to invoke this feature, it would be trivial to add an angle of motion check which would make it much less prone to accidental use. ------------------------------------------------- diff -u -r1.106 gtkentry.c --- gtk/gtkentry.c 2001/02/13 05:44:47 1.106 +++ gtk/gtkentry.c 2001/02/16 10:05:42 @@ -1145,8 +1145,20 @@ } else { + int width, height; tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset); + gdk_window_get_size (entry->text_area, &width, &height); + if ((event->y - entry->drag_start_y) <= -height) + { /* user has dragged up so select to begining of line */ + /* possibly pango problems? */ + tmp_pos = 0; + } + if ((event->y - entry->drag_start_y) >= height) + { /* user has dragged down so select to end of line */ + /* possibly pango problems? */ + tmp_pos = entry->text_length; + } if (tmp_pos != entry->current_pos) { entry->current_pos = tmp_pos;
Applying patch to do this. Instead of using relative motion, I decided to go with absolute motion, so it makes a bit more sense when it triggers. else { - tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset); + gint height; + gdk_window_get_size (entry->text_area, NULL, &height); + + if (event->y < 0) + tmp_pos = 0; + else if (event->y >= height) + tmp_pos = entry->text_length; + else + tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset); + gtk_entry_set_positions (entry, tmp_pos, -1); } No pango considerations here - up should always mean go to the logical beginning of the line down to the logical end of the line.
*** Bug 626696 has been marked as a duplicate of this bug. ***
for ref, this was pushed as commit 6fbd8b0d08acc35b8b8828506b2e0aec4e165a2e