Code

Fix and improve status refreshing after updating
authorJonas Fonseca <fonseca@diku.dk>
Thu, 27 Mar 2008 10:47:00 +0000 (11:47 +0100)
committerJonas Fonseca <fonseca@diku.dk>
Thu, 27 Mar 2008 19:45:22 +0000 (20:45 +0100)
Update the view offset so the current line is already visible.
This requires that the display is split or initialized before
starting to load the view so status_open has the view->height
available.

tig.c

diff --git a/tig.c b/tig.c
index dc48eed4ebac1a882dd9d26d39944e5ed6603bd7..25a77ff04a730ca7ede52609b3bbf0b6ac66ea06 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -2278,18 +2278,6 @@ open_view(struct view *prev, enum request request, enum open_flags flags)
                return;
        }
 
-       if (view->ops->open) {
-               if (!view->ops->open(view)) {
-                       report("Failed to load %s view", view->name);
-                       return;
-               }
-
-       } else if ((reload || strcmp(view->vid, view->id)) &&
-                  !begin_update(view)) {
-               report("Failed to load %s view", view->name);
-               return;
-       }
-
        if (split) {
                display[1] = view;
                if (!backgrounded)
@@ -2307,6 +2295,18 @@ open_view(struct view *prev, enum request request, enum open_flags flags)
            (nviews == 1 && base_view != display[0]))
                resize_display();
 
+       if (view->ops->open) {
+               if (!view->ops->open(view)) {
+                       report("Failed to load %s view", view->name);
+                       return;
+               }
+
+       } else if ((reload || strcmp(view->vid, view->id)) &&
+                  !begin_update(view)) {
+               report("Failed to load %s view", view->name);
+               return;
+       }
+
        if (split && prev->lineno - prev->offset >= prev->height) {
                /* Take the title line into account. */
                int lines = prev->lineno - prev->offset - prev->height + 1;
@@ -3964,6 +3964,8 @@ status_open(struct view *view)
                prev_lineno = view->lines - 1;
        while (prev_lineno < view->lines && !view->line[prev_lineno].data)
                prev_lineno++;
+       while (prev_lineno > 0 && !view->line[prev_lineno].data)
+               prev_lineno--;
 
        /* If the above fails, always skip the "On branch" line. */
        if (prev_lineno < view->lines)
@@ -3971,6 +3973,11 @@ status_open(struct view *view)
        else
                view->lineno = 1;
 
+       if (view->lineno < view->offset)
+               view->offset = view->lineno;
+       else if (view->offset + view->height <= view->lineno)
+               view->offset = view->lineno - view->height + 1;
+
        return TRUE;
 }