Download raw body.
tog: tree view page up/down bugs
On Wed, Nov 25, 2020 at 12:08:29AM +0100, Stefan Sperling wrote: > This should fix page-up/page-down behaviour in 'tog tree'. My previous patch displayed a bogus .. parent directory entry after page-up was pressed in the root directory. Fixed here. diff d2233537e59866c345cb18df7fdcd11d056ec3bd 6ac8b5b899647b3eab0d468abd7465cc51324dfe blob - feaac17d0e83e59b9ef24e80a5f347f16db2f891 blob + 44191fafa3551d1553ea8618805e6e2dc78cc822 --- tog/tog.c +++ tog/tog.c @@ -4998,7 +4998,7 @@ tree_scroll_up(struct tog_view *view, struct got_tree_object *tree, int isroot) { struct got_tree_entry *te; - int i; + int i = 0; if (*first_displayed_entry == NULL) return; @@ -5010,17 +5010,20 @@ tree_scroll_up(struct tog_view *view, return; } - i = 0; - while (*first_displayed_entry && i < maxscroll) { - *first_displayed_entry = got_tree_entry_get_prev(tree, - *first_displayed_entry); - i++; + if (*first_displayed_entry) { + te = got_tree_entry_get_prev(tree, *first_displayed_entry); + while (te && i++ < maxscroll) { + *first_displayed_entry = te; + te = got_tree_entry_get_prev(tree, te); + if (te == NULL && !isroot) { + *first_displayed_entry = NULL; + break; + } + } } - if (!isroot && te == got_object_tree_get_first_entry(tree) && i < maxscroll) - *first_displayed_entry = NULL; } -static int +static void tree_scroll_down(struct got_tree_entry **first_displayed_entry, int maxscroll, struct got_tree_entry *last_displayed_entry, struct got_tree_object *tree) @@ -5041,7 +5044,6 @@ tree_scroll_down(struct got_tree_entry **first_display next = got_tree_entry_get_next(tree, next); } } - return n; } static const struct got_error * @@ -5366,7 +5368,7 @@ input_tree_view(struct tog_view **new_view, struct tog const struct got_error *err = NULL; struct tog_tree_view_state *s = &view->state.tree; struct tog_view *log_view; - int begin_x = 0, nscrolled; + int begin_x = 0; switch (ch) { case 'i': @@ -5407,13 +5409,16 @@ input_tree_view(struct tog_view **new_view, struct tog break; case KEY_PPAGE: case CTRL('b'): + if (s->tree == s->root) { + if (got_object_tree_get_first_entry(s->tree) == + s->first_displayed_entry) + s->selected = 0; + } else { + if (s->first_displayed_entry == NULL) + s->selected = 0; + } tree_scroll_up(view, &s->first_displayed_entry, - MAX(0, view->nlines - 4 - s->selected), s->tree, - s->tree == s->root); - s->selected = 0; - if (got_object_tree_get_first_entry(s->tree) == - s->first_displayed_entry && s->tree != s->root) - s->first_displayed_entry = NULL; + MAX(0, view->nlines - 3), s->tree, s->tree == s->root); break; case 'j': case KEY_DOWN: @@ -5437,18 +5442,8 @@ input_tree_view(struct tog_view **new_view, struct tog s->selected = s->ndisplayed - 1; break; } - nscrolled = tree_scroll_down(&s->first_displayed_entry, - view->nlines, s->last_displayed_entry, s->tree); - if (nscrolled < view->nlines) { - int ndisplayed = 0; - struct got_tree_entry *te; - te = s->first_displayed_entry; - do { - ndisplayed++; - te = got_tree_entry_get_next(s->tree, te); - } while (te); - s->selected = ndisplayed - 1; - } + tree_scroll_down(&s->first_displayed_entry, view->nlines - 3, + s->last_displayed_entry, s->tree); break; case KEY_ENTER: case '\r':
tog: tree view page up/down bugs