Index: src/vte.c
===================================================================
RCS file: /cvs/gnome/vte/src/vte.c,v retrieving revision 1.385 diff -u
-p -r1.385 vte.c --- src/vte.c 15 Sep 2003 18:51:29 -0000 1.385 +++
src/vte.c 14 Oct 2003 16:05:31 -0000 @@ -681,6 +681,14 @@
vte_terminal_scroll_region(VteTerminal *
 	    (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) {
@@ -2180,6 +2188,9 @@ vte_sequence_handler_al(VteTerminal *ter
 		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
@@ -2196,9 +2207,6 @@ vte_sequence_handler_al(VteTerminal *ter
 		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;
@@ -2811,6 +2819,9 @@ vte_sequence_handler_dl(VteTerminal *ter
 		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
@@ -2821,9 +2832,6 @@ vte_sequence_handler_dl(VteTerminal *ter
 		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;
@@ -3668,12 +3676,12 @@ vte_sequence_handler_sr(VteTerminal *ter
 	}
 
 	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);
@@ -5219,6 +5227,8 @@ vte_sequence_handler_insert_lines(VteTer
 	} 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
@@ -5232,8 +5242,6 @@ vte_sequence_handler_insert_lines(VteTer
 				 &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. */
@@ -5269,6 +5277,8 @@ vte_sequence_handler_delete_lines(VteTer
 	} 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
@@ -5282,8 +5292,6 @@ vte_sequence_handler_delete_lines(VteTer
 				 &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. */
@@ -10605,11 +10613,11 @@ vte_terminal_handle_scroll(VteTerminal *
 	/* Read the new adjustment value and save the difference. */
 	adj = floor(gtk_adjustment_get_value(terminal->adjustment));
 	dy = adj - screen->scroll_delta;
-	screen->scroll_delta = adj;
 	if (dy != 0) {
-		vte_terminal_match_contents_clear(terminal);
 		vte_terminal_scroll_region(terminal, screen->scroll_delta,
 					   terminal->row_count, -dy);
+		screen->scroll_delta = adj;
+		vte_terminal_match_contents_clear(terminal);
 		vte_terminal_emit_text_scrolled(terminal, dy);
 		vte_terminal_emit_contents_changed(terminal);
 	}
