@@ -213,6 +213,24 @@ private Button createActionButton(Composite parent, int style, Image image, Stri
213213 return result ;
214214 }
215215
216+ @ Override
217+ public Point computeSize (int widthHint , int heightHint , boolean changed ) {
218+ if (this .sourceViewer == null ) {
219+ return super .computeSize (widthHint , heightHint , changed );
220+ }
221+
222+ StyledText textWidget = this .sourceViewer .getTextWidget ();
223+ if (textWidget == null || textWidget .isDisposed ()) {
224+ return super .computeSize (widthHint , heightHint , changed );
225+ }
226+
227+ Point textSize = textWidget .computeSize (widthHint , SWT .DEFAULT , changed );
228+ Rectangle trim = computeTrim (0 , 0 , textSize .x , getSourceViewerHeight (textWidget , textSize ));
229+ int width = widthHint == SWT .DEFAULT ? trim .width : widthHint ;
230+ int height = heightHint == SWT .DEFAULT ? trim .height : heightHint ;
231+ return new Point (Math .max (0 , width ), Math .max (0 , height ));
232+ }
233+
216234 private void refreshScrollerLayout () {
217235 if (this .sourceViewer == null ) {
218236 return ;
@@ -224,16 +242,20 @@ private void refreshScrollerLayout() {
224242 }
225243 Point size = textWidget .computeSize (SWT .DEFAULT , SWT .DEFAULT );
226244 Rectangle clientArea = this .getClientArea ();
227- // remove scroll-bar height
228- ScrollBar horizontalBar = textWidget .getHorizontalBar ();
229- int scrollbarHeight = horizontalBar != null ? horizontalBar .getSize ().y : 0 ;
230- int height = size .y - scrollbarHeight ;
245+ int height = getSourceViewerHeight (textWidget , size );
231246 // Set bounds on SourceViewer's control (the direct child), not just the textWidget
232247 this .sourceViewer .getControl ().setBounds (0 , 0 , clientArea .width , height );
233248 textWidget .redraw ();
234249 });
235250 }
236251
252+ private int getSourceViewerHeight (StyledText textWidget , Point textSize ) {
253+ // remove scroll-bar height
254+ ScrollBar horizontalBar = textWidget .getHorizontalBar ();
255+ int scrollbarHeight = horizontalBar != null ? horizontalBar .getSize ().y : 0 ;
256+ return Math .max (0 , textSize .y - scrollbarHeight );
257+ }
258+
237259 private void insert (Event e ) {
238260 String content = this .sourceViewer .getDocument ().get ();
239261 if (StringUtils .isNotEmpty (content )) {
0 commit comments