Download raw body.
tog: tree view move-to-parent bug
On Wed, Nov 25, 2020 at 02:37:57PM +0100, Christian Weisgerber wrote: > I'm sooorry... here's another problem in the tree view: No need to apologize. Your reports a very useful! I should apologize for writing such sloppy code ;) > * Shrink terminal to 10 lines height. > * In the got repository, run "tog tree lib". > * Hit backspace to move to the parent directory. > * Now the selected entry is outside the visible area and weirdness > ensues. > => If you move up, in sufficient single steps or by a page, the > selection eventually moves to a visible entry. > => If you move down instead, you can move all the way to the last > entry and there is still no visible selection. > => If you have reached the bottom and now hit UP a few times, > eventually the last entry will be selected. This happens because the tree view attempts to keep the scroll position of an already visited parent directory intact. But if we start out by viewing a subtree and then move up, the scroll position of the parent isn't actually available since the parent tree was never nagivated by the user. In this case tree_view_walk_path() has to fill in some values. The current values are bogus and result in the behaviour you have found. The only parent entry we know about in this case is the one which was traversed to reach the child. I believe the best we can do is to lock the parent's scroll position such that the traversed child entry appears at the top of the list if moving up to the parent's view. If we then navigate down again and return, the parent's scroll position will start to be retained and restored properly. ok? diff 6bd1f2c9e69e5b58e11f16329f45de10a751d2cb /home/stsp/src/got blob - 1f237865b895aeaddf0db2aa913b97b6b8a8ec75 file + tog/tog.c --- tog/tog.c +++ tog/tog.c @@ -1819,7 +1819,10 @@ open_diff_view_for_commit(struct tog_view **new_view, static const struct got_error * tree_view_visit_subtree(struct got_tree_object *subtree, - struct tog_tree_view_state *s) + struct tog_tree_view_state *s, + struct got_tree_entry *first_displayed_entry, + struct got_tree_entry *selected_entry, + int selected) { struct tog_parent_tree *parent; @@ -1828,9 +1831,9 @@ tree_view_visit_subtree(struct got_tree_object *subtre return got_error_from_errno("calloc"); parent->tree = s->tree; - parent->first_displayed_entry = s->first_displayed_entry; - parent->selected_entry = s->selected_entry; - parent->selected = s->selected; + parent->first_displayed_entry = first_displayed_entry; + parent->selected_entry = selected_entry; + parent->selected = selected; TAILQ_INSERT_HEAD(&s->parents, parent, entry); s->tree = subtree; s->selected = 0; @@ -1907,7 +1910,8 @@ tree_view_walk_path(struct tog_tree_view_state *s, if (err) break; - err = tree_view_visit_subtree(tree, s); + err = tree_view_visit_subtree(tree, s, + s->selected_entry, s->selected_entry, 0); if (err) { got_object_tree_close(tree); break; @@ -5468,7 +5472,9 @@ input_tree_view(struct tog_view **new_view, struct tog got_tree_entry_get_id(s->selected_entry)); if (err) break; - err = tree_view_visit_subtree(subtree, s); + err = tree_view_visit_subtree(subtree, s, + s->first_displayed_entry, s->selected_entry, + s->selected); if (err) { got_object_tree_close(subtree); break;
tog: tree view move-to-parent bug