--- a/src/vte.c
+++ b/src/vte.c
@@ -8068,13 +8068,36 @@
 	}
 	if (old_rows != terminal->row_count || old_columns != terminal->column_count) {
 		VteScreen *screen = terminal->pvt->screen;
-		glong visible_rows = MIN (old_rows, _vte_ring_length (screen->row_data));
-		if (terminal->row_count < visible_rows) {
-			glong delta = visible_rows - terminal->row_count;
+		glong old_visible_rows = MIN (old_rows, _vte_ring_length (screen->row_data));
+		glong ring_length=_vte_ring_length (screen->row_data);
+		/* Subtract the scrolling offset from the row start so that the
+		 * resulting rectangle is relative to the visible portion of the
+		 * buffer. */
+		glong cursor_row = screen->cursor_current.row-screen->insert_delta;
+
+		if (terminal->row_count < old_visible_rows && 
+			ring_length > terminal->row_count && 
+			cursor_row>=terminal->row_count) {
+			glong delta = old_visible_rows - terminal->row_count;
+			/*limit scroll delta to current cursor position*/
+			if(screen->scroll_delta+delta>screen->cursor_current.row)
+				delta=screen->cursor_current.row-screen->scroll_delta;
+			if(screen->insert_delta+delta>screen->cursor_current.row)
+				delta=screen->cursor_current.row-screen->insert_delta;	
 			screen->insert_delta += delta;
 			vte_terminal_queue_adjustment_value_changed (
 					terminal,
 					screen->scroll_delta + delta);
+		}else
+		if (terminal->row_count > old_visible_rows &&
+			ring_length > terminal->row_count) {
+			glong delta = old_visible_rows - terminal->row_count;
+			/*limit scroll delta to current cursor position*/
+			if(screen->scroll_delta+delta>screen->cursor_current.row)
+				delta=screen->cursor_current.row-screen->scroll_delta;
+			if(screen->insert_delta+delta>screen->cursor_current.row)
+				delta=screen->cursor_current.row-screen->insert_delta;				
+			screen->insert_delta += delta;
 		}
 		gtk_widget_queue_resize_no_redraw (&terminal->widget);
 		/* Our visible text changed. */
--- a/src/vteseq.c
+++ b/src/vteseq.c
@@ -1136,7 +1136,7 @@
 			rowdata = _vte_ring_index_writable (screen->row_data, i);
 			g_assert(rowdata != NULL);
 		} else {
-			rowdata = _vte_terminal_ring_append (terminal, FALSE);
+			continue;//just skip non existent row
 		}
 		/* Pad out the row. */
 		_vte_row_data_fill (rowdata, &screen->fill_defaults, terminal->column_count);
