summarylogtreecommitdiffstats
path: root/lines-rewrap.patch
blob: 5acbbb99e06baf57f1954fad6cb656360aa05553 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
--- src/screen.C
+++ src/screen.C
@@ -293,7 +293,6 @@
 
       int common_col = min (prev_ncol, ncol);
 
-      // resize swap_buf, blank drawn_buf
       for (int row = min (nrow, prev_nrow); row--; )
         {
           scr_blank_screen_mem (drawn_buf [row], DEFAULT_RSTYLE);
@@ -307,7 +306,6 @@
       int pend = MOD (term_start + top_row  , prev_total_rows);
       int q    = total_rows; // rewrapped row
 
-#if ENABLE_FRILLS
       if ((rewrap_always || top_row) && !rewrap_never)
         {
           // Re-wrap lines. This is rather ugly, possibly because I am too dumb
@@ -389,35 +387,38 @@
               scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE);
             }
           while (p != pend && q > 0);
+
+          term_start = total_rows - nrow;
+          top_row = q - term_start;
+
+          // make sure all terminal lines exist
+          while (top_row > 0)
+            scr_blank_screen_mem (ROW (--top_row), DEFAULT_RSTYLE);
         }
       else
-#endif
         {
-          // wing, instead of wrap
-          screen.cur.row += nrow - prev_nrow;
 
-          do
+          // if no scrollback exists (yet), wing, instead of wrap
+
+          for (int row = min (nrow, prev_nrow); row--; )
             {
-              p = MOD (p - 1, prev_total_rows);
-              q--;
 
-              copy_line (row_buf [q], prev_row_buf [p]);
+              line_t &src = prev_row_buf [MOD (term_start + row, prev_total_rows)];
+              line_t &dst = row_buf [row];
+
+              copy_line (dst, src);
             }
-          while (p != pend && q > 0);
-        }
 
-      term_start = total_rows - nrow;
-      top_row = q - term_start;
+          for (int row = prev_nrow; row < nrow; row++)
+            scr_blank_screen_mem (row_buf [row], DEFAULT_RSTYLE);
 
-      // make sure all terminal lines exist
-      while (top_row > 0)
-        scr_blank_screen_mem (ROW (--top_row), DEFAULT_RSTYLE);
+          term_start = 0;
+        }
 
       clamp_it (screen.cur.row, 0, nrow - 1);
       clamp_it (screen.cur.col, 0, ncol - 1);
     }
 
-  // ensure drawn_buf, swap_buf and terminal rows are all initialized
   for (int row = nrow; row--; )
     {
       if (!ROW       (row).valid ()) scr_blank_screen_mem (ROW       (row), DEFAULT_RSTYLE);