reset screen offset of top line if it exceeds the number of screens
authorSven Verdoolaege <skimo@kotnet.org>
Sat, 26 Feb 2011 13:56:21 +0000 (26 14:56 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 26 Feb 2011 13:56:21 +0000 (26 14:56 +0100)
Some operations such as changing the tab size may change the number of
screens needed to display a line and may therefore result in the current
screen offset to exceed this number of screens.
This could in turn result in the entire screen not being populated properly.

This patch detects and corrects this situation while populating the
screen after reformatting.

Problem reported and fixed by patrick keshishian <pkeshish@gmail.com>

vi/vs_smap.c

index db4c9bb..92284b7 100644 (file)
@@ -224,6 +224,16 @@ vs_sm_fill(SCR *sp, db_recno_t lno, pos_t pos)
 top:                   HMAP->lno = lno;
                        HMAP->coff = 0;
                        HMAP->soff = 1;
+               } else {
+                       /*
+                        * If number of lines HMAP->lno (top line) spans
+                        * changed due to, say reformatting, and now is
+                        * fewer than HMAP->soff, reset so the line is
+                        * redrawn at the top of the screen.
+                        */
+                       cnt = vs_screens(sp, HMAP->lno, NULL);
+                       if (cnt < HMAP->soff)
+                               HMAP->soff = 1;
                }
                /* If we fail, just punt. */
                for (p = HMAP, cnt = sp->t_rows; --cnt; ++p)