resize from the top.
authorAurélien Aptel <aurelien.aptel@gmail.com>
Wed, 1 Sep 2010 23:42:03 +0000 (01:42 +0200)
committerAurélien Aptel <aurelien.aptel@gmail.com>
Wed, 1 Sep 2010 23:42:03 +0000 (01:42 +0200)
st.c

diff --git a/st.c b/st.c
index f7f9de8..ed5481d 100644 (file)
--- a/st.c
+++ b/st.c
@@ -1060,12 +1060,25 @@ tresize(int col, int row) {
        int i;
        int minrow = MIN(row, term.row);
        int mincol = MIN(col, term.col);
+       int slide = term.c.y - row + 1;
 
        if(col < 1 || row < 1)
                return;
 
-       /* free uneeded rows */
-       for(i = row; i < term.row; i++) {
+       /* free unneeded rows */
+       i = 0;
+       if(slide > 0) {
+               /* slide screen to keep cursor where we expect it -
+                * tscrollup would work here, but we can optimize to
+                * memmove because we're freeing the earlier lines */
+               for(/* i = 0 */; i < slide; i++) {
+                       free(term.line[i]);
+                       free(term.alt[i]);
+               }
+               memmove(term.line, term.line + slide, row * sizeof(Line));
+               memmove(term.alt, term.alt + slide, row * sizeof(Line));
+       }
+       for(i += row; i < term.row; i++) {
                free(term.line[i]);
                free(term.alt[i]);
        }