Better method for row shrinking.
authorTimo Korvola <tkorvola@iki.fi>
Tue, 6 Feb 2018 22:25:46 +0000 (00:25 +0200)
committerTimo Korvola <tkorvola@iki.fi>
Sat, 10 Feb 2018 12:57:36 +0000 (14:57 +0200)
Shrink the screen so that the cursor will normally be on the last row.

#42: Handle terminal resizing

src/curses/ux_screen.c

index 35ef0cb9efd738c49f7206b55f4bfceb06e41026..a469f359d13dd7e7854a3091e14a847e0b692001 100644 (file)
@@ -211,20 +211,15 @@ void unix_resize_display(void)
     endwin();
     refresh();
     unix_get_terminal_size();
-
     if (lines > h_screen_rows) {
-        /* Lose some of the topmost lines that won't fit. */
-        int lost = lines - h_screen_rows;
-        /* Don't lose the cursor position though,
-           drop some trailing lines instead. */
-        if (y < lost)
-            lost = y;
         lines = h_screen_rows;
-        y -= lost;
-        pos += cols * lost;
+        if (y >= h_screen_rows) {
+            /* Lose some topmost lines to keep the cursor on screen. */
+            int lost = y + 1 - h_screen_rows;
+            y = h_screen_rows - 1;
+            pos += cols * lost;
+        }
     }
-    if (y >= h_screen_rows)
-        y = h_screen_rows - 1;
     if (x >= h_screen_cols)
         x = h_screen_cols - 1;
     restore_screen(lines, cols, pos);