diff --git a/src/dirlist.c b/src/dirlist.c index db0bd0dbe2870d7c1656a2c9304dd988645efbe4..6fbe07f02e6a9dd3a5784b6b33b97558de39a908 100644 --- a/src/dirlist.c +++ b/src/dirlist.c @@ -170,10 +170,9 @@ void dirlist_fixup() { } /* no selected items found after one pass? select the first visible item */ - if(!selected) { - selected = dirlist_next(NULL); - selected->flags |= FF_BSEL; - } + if(!selected) + if((selected = dirlist_next(NULL))) + selected->flags |= FF_BSEL; } @@ -239,13 +238,17 @@ struct dir *dirlist_prev(struct dir *d) { } -/* this function assumes that 'selected' is valid and points to a visible item */ struct dir *dirlist_get(int i) { struct dir *t = selected, *d; if(!head) return NULL; + if(ISHIDDEN(selected)) { + selected = dirlist_next(NULL); + return selected; + } + /* i == 0? return the selected item */ if(!i) return selected; @@ -273,7 +276,7 @@ struct dir *dirlist_get(int i) { void dirlist_select(struct dir *d) { - if(!head || ISHIDDEN(d) || d->parent != head->parent) + if(!d || !head || ISHIDDEN(d) || d->parent != head->parent) return; selected->flags &= ~FF_BSEL;