Code

Improve restoring of the view position to bound the offset
authorJonas Fonseca <fonseca@diku.dk>
Sat, 7 Feb 2009 15:25:54 +0000 (16:25 +0100)
committerJonas Fonseca <fonseca@diku.dk>
Sat, 7 Feb 2009 20:23:55 +0000 (21:23 +0100)
tig.c

diff --git a/tig.c b/tig.c
index 8a55aab9288ab2c3ea861c619649324937f27a9e..398db4d47a1c89754dc8363f0895c7c09ab0ac59 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -2675,16 +2675,17 @@ restore_view_position(struct view *view)
                return FALSE;
        }
 
-       if (view->p_lineno >= view->lines) {
+       if (view->p_lineno >= view->lines)
                view->p_lineno = view->lines > 0 ? view->lines - 1 : 0;
-               if (view->p_offset >= view->p_lineno) {
-                       unsigned long half = view->height / 2;
 
-                       if (view->p_lineno > half)
-                               view->p_offset = view->p_lineno - half;
-                       else
-                               view->p_offset = 0;
-               }
+       if (view->p_offset > view->p_lineno ||
+           view->p_offset + view->height <= view->p_lineno) {
+               unsigned long half = view->height / 2;
+
+               if (view->p_lineno > half)
+                       view->p_offset = view->p_lineno - half;
+               else
+                       view->p_offset = 0;
        }
 
        if (view_is_displayed(view) &&