- /* Find a the first search result later than it. They're sorted so we could
- * actually do much better than this if necessary. */
- for(int n = 0; n < choose_n_search_references; ++n) {
+ /* Compute bounds for searching over the array in the right direction */
+ const int first = direction > 0 ? 0 : choose_n_search_references - 1;
+ const int limit = direction > 0 ? choose_n_search_references : -1;
+ /* Find the first/last currently visible row */
+ GtkTreePath *limitpath;
+ if(!choose_get_visible_range(GTK_TREE_VIEW(choose_view),
+ direction < 0 ? &limitpath : 0,
+ direction > 0 ? &limitpath : 0))
+ return;
+ /* Find a the first search result later/earlier than it. They're sorted so
+ * we could actually do much better than this if necessary. */
+ for(int n = first; n != limit; n += direction) {