- while(gtk_events_pending())
- gtk_main_iteration();
-
- /* Move the pager to the last visible character in the buffer */
- gint scroll_distance = move_pager_and_get_scroll_distance(textview);
-
- if(scroll_distance == 0)
- stop_paging(textview);
-
- return TRUE; /* block further handlers */
+ GtkWidget *scrolledwindow = gtk_widget_get_parent(GTK_WIDGET(textview));
+ GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrolledwindow));
+ gdouble step_increment, page_size, upper, lower, value;
+ g_object_get(adj,
+ "page-size", &page_size,
+ "step-increment", &step_increment,
+ "upper", &upper,
+ "lower", &lower,
+ "value", &value,
+ NULL);
+
+ switch (event->keyval) {
+ case GDK_space: case GDK_KP_Space: case GDK_Page_Down: case GDK_KP_Page_Down:
+ gtk_adjustment_set_value(adj, CLAMP(value + page_size, lower, upper - page_size));
+ return TRUE;
+ case GDK_Page_Up: case GDK_KP_Page_Up:
+ gtk_adjustment_set_value(adj, CLAMP(value - page_size, lower, upper - page_size));
+ return TRUE;
+ case GDK_Return: case GDK_KP_Enter:
+ gtk_adjustment_set_value(adj, CLAMP(value + step_increment, lower, upper - page_size));
+ return TRUE;
+ /* don't handle "up" and "down", they're used for input history */
+ }
+
+ return FALSE; /* if the key wasn't handled here, pass it to other handlers */