--- vte-0.11.11/src/vte.c.orig	2004-10-29 18:26:40.826233176 -0400
+++ vte-0.11.11/src/vte.c	2004-10-29 18:27:07.303208064 -0400
@@ -718,6 +718,14 @@
 	    (count == terminal->row_count) &&
 	    (terminal->pvt->scroll_lock_count == 0)) {
 		height = terminal->char_height;
+		
+		/* If we scroll with invalid areas, we will copy
+		 * invalid contents around the screen. So, we must
+		 * handle pending redraws first.
+		 */
+		gdk_window_process_updates (GTK_WIDGET(terminal)->window,
+					    FALSE);
+
 		gdk_window_scroll((GTK_WIDGET(terminal))->window,
 				  0, delta * height);
 		if (delta > 0) {
@@ -2284,6 +2292,9 @@
 		param = g_value_get_long(value);
 	}
 
+	/* Update the display. */
+	vte_terminal_scroll_region(terminal, start, end - start + 1, param);
+
 	/* Insert the right number of lines. */
 	for (i = 0; i < param; i++) {
 		/* Clear a line off the end of the region and add one to the
@@ -2301,9 +2312,6 @@
 		vte_terminal_adjust_adjustments(terminal, FALSE);
 	}
 
-	/* Update the display. */
-	vte_terminal_scroll_region(terminal, start, end - start + 1, param);
-
 	/* We've modified the display.  Make a note of it. */
 	terminal->pvt->text_deleted_count++;
 	return FALSE;
@@ -2920,6 +2928,9 @@
 		param = g_value_get_long(value);
 	}
 
+	/* Update the display. */
+	vte_terminal_scroll_region(terminal, start, end - start + 1, -param);
+
 	/* Delete the right number of lines. */
 	for (i = 0; i < param; i++) {
 		/* Clear a line off the end of the region and add one to the
@@ -2930,9 +2941,6 @@
 		vte_terminal_adjust_adjustments(terminal, FALSE);
 	}
 
-	/* Update the display. */
-	vte_terminal_scroll_region(terminal, start, end - start + 1, -param);
-
 	/* We've modified the display.  Make a note of it. */
 	terminal->pvt->text_deleted_count++;
 	return FALSE;
@@ -3883,12 +3891,12 @@
 	}
 
 	if (screen->cursor_current.row == start) {
+		/* Update the display. */
+		vte_terminal_scroll_region(terminal, start, end - start + 1, 1);
 		/* If we're at the top of the scrolling region, add a
 		 * line at the top to scroll the bottom off. */
 		vte_remove_line_internal(terminal, end);
 		vte_insert_line_internal(terminal, start);
-		/* Update the display. */
-		vte_terminal_scroll_region(terminal, start, end - start + 1, 1);
 		vte_invalidate_cells(terminal,
 				     0, terminal->column_count,
 				     start, 2);
@@ -5435,6 +5443,8 @@
 	} else {
 		end = screen->insert_delta + terminal->row_count - 1;
 	}
+	/* Update the display. */
+	vte_terminal_scroll_region(terminal, row, end - row + 1, param);
 	/* Insert the new lines at the cursor. */
 	for (i = 0; i < param; i++) {
 		/* Clear a line off the end of the region and add one to the
@@ -5449,8 +5459,6 @@
 				 &screen->fill_defaults,
 				 terminal->column_count);
 	}
-	/* Update the display. */
-	vte_terminal_scroll_region(terminal, row, end - row + 1, param);
 	/* Adjust the scrollbars if necessary. */
 	vte_terminal_adjust_adjustments(terminal, FALSE);
 	/* We've modified the display.  Make a note of it. */
@@ -5486,6 +5494,8 @@
 	} else {
 		end = screen->insert_delta + terminal->row_count - 1;
 	}
+	/* Update the display. */
+	vte_terminal_scroll_region(terminal, row, end - row + 1, -param);
 	/* Clear them from below the current cursor. */
 	for (i = 0; i < param; i++) {
 		/* Insert a line at the end of the region and remove one from
@@ -5500,8 +5510,6 @@
 				 &screen->fill_defaults,
 				 terminal->column_count);
 	}
-	/* Update the display. */
-	vte_terminal_scroll_region(terminal, row, end - row + 1, -param);
 	/* Adjust the scrollbars if necessary. */
 	vte_terminal_adjust_adjustments(terminal, FALSE);
 	/* We've modified the display.  Make a note of it. */
@@ -11012,9 +11020,9 @@
 		    fprintf(stderr, "Scrolling by %ld\n", dy);
 	      }
 #endif
-		vte_terminal_match_contents_clear(terminal);
 		vte_terminal_scroll_region(terminal, screen->scroll_delta,
 					   terminal->row_count, -dy);
+		vte_terminal_match_contents_clear(terminal);
 		vte_terminal_emit_text_scrolled(terminal, dy);
 		vte_terminal_emit_contents_changed(terminal);
 	}
