@@ -689,7 +689,8 @@ private void doubleBufferPaint(GC dest) {
689689 if (fBuffer == null ) {
690690 fBuffer = newFullBufferImage (size );
691691 } else {
692- doPaint (visibleLines , size );
692+ GC bufferGC = new GC (fBuffer );
693+ doPaint (bufferGC , visibleLines , size .x , size .y , true );
693694 }
694695 dest .drawImage (fBuffer , 0 , 0 );
695696 }
@@ -700,30 +701,27 @@ private Image newFullBufferImage(Point size) {
700701 if (lines == null ) {
701702 return ;
702703 }
703- // We redraw everything; paint directly into the buffer
704- initializeGC (gc , 0 , 0 , imageWidth , imageHeight );
705- doPaint (gc , lines );
704+ doPaint (gc , lines , imageWidth , imageHeight , false );
706705 };
707706 return new Image (fCanvas .getDisplay (), imageGcDrawer , size .x , size .y );
708707 }
709708
710- private void doPaint (ILineRange visibleLines , Point size ) {
711- GC bufferGC = new GC (fBuffer );
709+ private void doPaint (GC bufferGC , ILineRange visibleLines , int fullWidth , int fullHeight , boolean bufferStillValid ) {
712710 Image newBuffer = null ;
713711 try {
714712 int topPixel = fCachedTextWidget .getTopPixel ();
715713 int bufferY = 0 ;
716- int bufferH = size . y ;
714+ int bufferH = fullHeight ;
717715 int numberOfLines = visibleLines .getNumberOfLines ();
718716 int dy = topPixel - fLastTopPixel ;
719717 int topModelLine = visibleLines .getStartLine ();
720718 int bottomModelLine = topModelLine + numberOfLines - 1 ;
721719 int bottomWidgetLine = JFaceTextUtil .modelLineToWidgetLine (fCachedTextViewer , bottomModelLine );
722720 boolean atEnd = bottomWidgetLine + 1 >= fCachedTextWidget .getLineCount ();
723- int height = size . y ;
724- if (dy != 0 && !atEnd && fLastTopPixel >= 0 && numberOfLines > 1 && numberOfLines == fLastNumberOfLines ) {
721+ int height = fullHeight ;
722+ if (dy != 0 && !atEnd && bufferStillValid && fLastTopPixel >= 0 && numberOfLines > 1 && numberOfLines == fLastNumberOfLines ) {
725723 int bottomPixel = fCachedTextWidget .getLinePixel (bottomWidgetLine + 1 );
726- if (dy > 0 && bottomPixel < size . y ) {
724+ if (dy > 0 && bottomPixel < fullHeight ) {
727725 // Can occur on GTK with static scrollbars; see bug 551320.
728726 height = bottomPixel ;
729727 }
@@ -734,20 +732,20 @@ private void doPaint(ILineRange visibleLines, Point size) {
734732 goodPixels = fLastHeight ;
735733 }
736734 if (dy < goodPixels ) {
737- bufferGC .copyArea (0 , dy , size . x , goodPixels - dy , 0 , 0 );
735+ bufferGC .copyArea (0 , dy , fullWidth , goodPixels - dy , 0 , 0 );
738736 bufferY = goodPixels - dy ;
739737 bufferH = height - bufferY ;
740738 } else {
741739 // Redraw everything.
742- height = size . y ;
740+ height = fullHeight ;
743741 dy = 0 ;
744742 }
745743 } else if (dy < 0 && -dy < height ) {
746- bufferGC .copyArea (0 , 0 , size . x , height + dy , 0 , -dy );
744+ bufferGC .copyArea (0 , 0 , fullWidth , height + dy , 0 , -dy );
747745 bufferY = 0 ;
748746 bufferH = -dy ;
749747 } else {
750- height = size . y ;
748+ height = fullHeight ;
751749 dy = 0 ;
752750 }
753751 } else {
@@ -770,18 +768,18 @@ private void doPaint(ILineRange visibleLines, Point size) {
770768 fLastBottomModelLine = bottomModelLine ;
771769 fLastHeight = height ;
772770 if (dy != 0 ) {
773- newBuffer = newBufferImage (size , bufferY , bufferH , visibleLines );
774- bufferGC .drawImage (newBuffer , 0 , bufferY , size . x , bufferH , 0 , bufferY , size . x , bufferH );
775- if (dy > 0 && bufferY + bufferH < size . y ) {
771+ newBuffer = newBufferImage (fullWidth , fullHeight , bufferY , bufferH , visibleLines );
772+ bufferGC .drawImage (newBuffer , 0 , bufferY , fullWidth , bufferH , 0 , bufferY , fullWidth , bufferH );
773+ if (dy > 0 && bufferY + bufferH < fullHeight ) {
776774 // Scrolled down in the text, but didn't use the full height of the Canvas: clear
777775 // the rest. Occurs on GTK with static scrollbars; the area cleared here is the
778776 // bit next to the horizontal scrollbar. See bug 551320.
779777 bufferGC .setBackground (getBackground (fCanvas .getDisplay ()));
780- bufferGC .fillRectangle (0 , bufferY + bufferH , size . x , size . y - bufferY - bufferH + 1 );
778+ bufferGC .fillRectangle (0 , bufferY + bufferH , fullWidth , fullHeight - bufferY - bufferH + 1 );
781779 }
782780 } else {
783781 // We redraw everything; paint directly into the buffer
784- initializeGC (bufferGC , 0 , 0 , size . x , size . y );
782+ initializeGC (bufferGC , 0 , 0 , fullWidth , fullHeight );
785783 doPaint (bufferGC , visibleLines );
786784 }
787785 } finally {
@@ -792,14 +790,14 @@ private void doPaint(ILineRange visibleLines, Point size) {
792790 }
793791 }
794792
795- private Image newBufferImage (Point size , int bufferY , int bufferH , final ILineRange visibleLines ) {
793+ private Image newBufferImage (int width , int height , int bufferY , int bufferH , final ILineRange visibleLines ) {
796794 ImageGcDrawer imageGcDrawer = (localGC , imageWidth , imageHeight ) -> {
797795 // Some rulers may paint outside the line region. Let them paint in a new image,
798796 // the copy the wanted bits.
799797 initializeGC (localGC , 0 , bufferY , imageWidth , bufferH );
800798 doPaint (localGC , visibleLines );
801799 };
802- return new Image (fCanvas .getDisplay (), imageGcDrawer , size . x , size . y );
800+ return new Image (fCanvas .getDisplay (), imageGcDrawer , width , height );
803801 }
804802
805803 private void initializeGC (GC gc , int x , int y , int width , int height ) {
0 commit comments