@ Override public void scrollLines ( int firstLine , int lastLine , int distance ) { // just ignore certain kinds of garbage: if ( distance == 0 || firstLine > lastLine ) { return ; } super . scrollLines ( firstLine , lastLine , distance ) ; // Save scroll hint for next refresh: ScrollHint newHint = new ScrollHint ( firstLine , lastLine , distance ) ; if ( scrollHint == null ) { // no scroll hint yet: use the new one: scrollHint = newHint ; } else //noinspection StatementWithEmptyBody if ( scrollHint == ScrollHint . INVALID ) { // scroll ranges already inconsistent since latest refresh! // leave at INVALID } else if ( scrollHint . matches ( newHint ) ) { // same range: just accumulate distance: scrollHint . distance += newHint . distance ; } else { // different scroll range: no scroll-optimization for next refresh this . scrollHint = ScrollHint . INVALID ; } }
Perform the scrolling and save scroll - range and distance in order to be able to optimize Terminal - update later .