From 539db82f2e00f9e3dd3d718acbd631b44b79092b Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 7 Feb 2009 16:25:54 +0100 Subject: [PATCH] Improve restoring of the view position to bound the offset --- tig.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tig.c b/tig.c index 8a55aab..398db4d 100644 --- 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) && -- 2.30.2