Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,24 @@ private Button createActionButton(Composite parent, int style, Image image, Stri
return result;
}

@Override
public Point computeSize(int widthHint, int heightHint, boolean changed) {
if (this.sourceViewer == null) {
return super.computeSize(widthHint, heightHint, changed);
}

StyledText textWidget = this.sourceViewer.getTextWidget();
if (textWidget == null || textWidget.isDisposed()) {
return super.computeSize(widthHint, heightHint, changed);
}

Point textSize = textWidget.computeSize(widthHint, SWT.DEFAULT, changed);
Rectangle trim = computeTrim(0, 0, textSize.x, getSourceViewerHeight(textWidget, textSize));
int width = widthHint == SWT.DEFAULT ? trim.width : widthHint;
int height = heightHint == SWT.DEFAULT ? trim.height : heightHint;
return new Point(Math.max(0, width), Math.max(0, height));
}

private void refreshScrollerLayout() {
if (this.sourceViewer == null) {
return;
Expand All @@ -224,16 +242,20 @@ private void refreshScrollerLayout() {
}
Point size = textWidget.computeSize(SWT.DEFAULT, SWT.DEFAULT);
Rectangle clientArea = this.getClientArea();
// remove scroll-bar height
ScrollBar horizontalBar = textWidget.getHorizontalBar();
int scrollbarHeight = horizontalBar != null ? horizontalBar.getSize().y : 0;
int height = size.y - scrollbarHeight;
int height = getSourceViewerHeight(textWidget, size);
// Set bounds on SourceViewer's control (the direct child), not just the textWidget
this.sourceViewer.getControl().setBounds(0, 0, clientArea.width, height);
textWidget.redraw();
});
}

private int getSourceViewerHeight(StyledText textWidget, Point textSize) {
// remove scroll-bar height
ScrollBar horizontalBar = textWidget.getHorizontalBar();
int scrollbarHeight = horizontalBar != null ? horizontalBar.getSize().y : 0;
return Math.max(0, textSize.y - scrollbarHeight);
}

private void insert(Event e) {
String content = this.sourceViewer.getDocument().get();
if (StringUtils.isNotEmpty(content)) {
Expand Down
Loading