Completion: Fix PageUp/Down, Shift+Tab and wrap

This is consistent with GTK+ (excluding Tab) and Firefox.

Fixes: https://bugs.launchpad.net/midori/+bug/905078
This commit is contained in:
Christian Dywan 2012-08-09 00:37:59 +02:00
parent 3c159386c8
commit 2e17639201

View file

@ -988,10 +988,6 @@ midori_location_action_key_press_event_cb (GtkEntry* entry,
/* Return FALSE to allow Escape to stop loading */ /* Return FALSE to allow Escape to stop loading */
return FALSE; return FALSE;
} }
case GDK_KEY_Page_Up:
case GDK_KEY_Page_Down:
if (!(location_action->popup && gtk_widget_get_visible (location_action->popup)))
return TRUE;
case GDK_KEY_Delete: case GDK_KEY_Delete:
case GDK_KEY_KP_Delete: case GDK_KEY_KP_Delete:
{ {
@ -1040,7 +1036,12 @@ midori_location_action_key_press_event_cb (GtkEntry* entry,
case GDK_KEY_KP_Up: case GDK_KEY_KP_Up:
case GDK_KEY_Tab: case GDK_KEY_Tab:
case GDK_KEY_ISO_Left_Tab: case GDK_KEY_ISO_Left_Tab:
case GDK_KEY_Page_Down:
case GDK_KEY_Page_Up:
{ {
if ((event->keyval == GDK_KEY_Page_Up || event->keyval == GDK_KEY_Page_Down) &&
!(location_action->popup && gtk_widget_get_visible (location_action->popup)))
return TRUE;
if (location_action->popup && gtk_widget_get_visible (location_action->popup)) if (location_action->popup && gtk_widget_get_visible (location_action->popup))
{ {
GtkTreeModel* model = location_action->completion_model; GtkTreeModel* model = location_action->completion_model;
@ -1050,22 +1051,45 @@ midori_location_action_key_press_event_cb (GtkEntry* entry,
gint selected = location_action->completion_index; gint selected = location_action->completion_index;
if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down
|| event->keyval == GDK_KEY_Tab || event->keyval == GDK_KEY_ISO_Left_Tab) || ((event->keyval == GDK_KEY_Tab || event->keyval == GDK_KEY_ISO_Left_Tab)
selected = MIN (selected + 1, matches -1); && !(event->state & GDK_SHIFT_MASK)))
else if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up) {
selected = selected + 1;
if (selected == matches)
selected = -1;
}
else if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up
|| ((event->keyval == GDK_KEY_Tab || event->keyval == GDK_KEY_ISO_Left_Tab)
&& (event->state & GDK_SHIFT_MASK)))
{ {
if (selected == -1) if (selected == -1)
selected = matches - 1; selected = matches - 1;
else else
selected = MAX (selected - 1, 0); selected = selected - 1;
} }
else if (event->keyval == GDK_KEY_Page_Down) else if (event->keyval == GDK_KEY_Page_Down)
{
if (selected == -1)
selected = 0;
else if (selected < matches - 1)
selected = MIN (selected + 14, matches -1); selected = MIN (selected + 14, matches -1);
else
selected = -1;
}
else if (event->keyval == GDK_KEY_Page_Up) else if (event->keyval == GDK_KEY_Page_Up)
{
if (selected == -1)
selected = matches - 1;
else if (selected > 0)
selected = MAX (selected - 14, 0); selected = MAX (selected - 14, 0);
else
selected = -1;
}
else if (event->keyval != GDK_KEY_KP_Delete && event->keyval != GDK_KEY_Delete) else if (event->keyval != GDK_KEY_KP_Delete && event->keyval != GDK_KEY_Delete)
g_assert_not_reached (); g_assert_not_reached ();
if (selected != -1)
{
path = gtk_tree_path_new_from_indices (selected, -1); path = gtk_tree_path_new_from_indices (selected, -1);
gtk_tree_view_set_cursor (GTK_TREE_VIEW (location_action->treeview), gtk_tree_view_set_cursor (GTK_TREE_VIEW (location_action->treeview),
path, NULL, FALSE); path, NULL, FALSE);
@ -1079,6 +1103,10 @@ midori_location_action_key_press_event_cb (GtkEntry* entry,
pango_layout_set_text (gtk_entry_get_layout (entry), uri, -1); pango_layout_set_text (gtk_entry_get_layout (entry), uri, -1);
g_free (uri); g_free (uri);
} }
}
else
gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (location_action->treeview)));
location_action->completion_index = selected; location_action->completion_index = selected;
return TRUE; return TRUE;
} }