From 7d65964b3c0cc55ebfa718b2f87d93e4f514897e Mon Sep 17 00:00:00 2001 From: xinyi-gong Date: Wed, 8 Jul 2026 17:38:42 +0800 Subject: [PATCH 1/3] Fix stale code block height during incremental chat layout --- .../ui/chat/SourceViewerComposite.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/SourceViewerComposite.java b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/SourceViewerComposite.java index b661f77b..6b36f928 100644 --- a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/SourceViewerComposite.java +++ b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/SourceViewerComposite.java @@ -213,6 +213,23 @@ 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); + int width = widthHint == SWT.DEFAULT ? textSize.x : widthHint; + int height = heightHint == SWT.DEFAULT ? getSourceViewerHeight(textWidget, textSize) : heightHint; + return new Point(Math.max(0, width), Math.max(0, height)); + } + private void refreshScrollerLayout() { if (this.sourceViewer == null) { return; @@ -224,16 +241,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 textSize.y - scrollbarHeight; + } + private void insert(Event e) { String content = this.sourceViewer.getDocument().get(); if (StringUtils.isNotEmpty(content)) { From cfcf0bbedba0839241b9278c42ad887525704f32 Mon Sep 17 00:00:00 2001 From: xinyi-gong Date: Wed, 8 Jul 2026 17:45:02 +0800 Subject: [PATCH 2/3] Clamp source viewer code block height --- .../copilot/eclipse/ui/chat/SourceViewerComposite.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/SourceViewerComposite.java b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/SourceViewerComposite.java index 6b36f928..5bba4f92 100644 --- a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/SourceViewerComposite.java +++ b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/SourceViewerComposite.java @@ -252,7 +252,7 @@ private int getSourceViewerHeight(StyledText textWidget, Point textSize) { // remove scroll-bar height ScrollBar horizontalBar = textWidget.getHorizontalBar(); int scrollbarHeight = horizontalBar != null ? horizontalBar.getSize().y : 0; - return textSize.y - scrollbarHeight; + return Math.max(0, textSize.y - scrollbarHeight); } private void insert(Event e) { From 6818631c8239cff9619795adf064404487427dfe Mon Sep 17 00:00:00 2001 From: xinyi-gong Date: Thu, 9 Jul 2026 13:30:10 +0800 Subject: [PATCH 3/3] Include source viewer trim in code block sizing --- .../copilot/eclipse/ui/chat/SourceViewerComposite.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/SourceViewerComposite.java b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/SourceViewerComposite.java index 5bba4f92..b1e737a8 100644 --- a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/SourceViewerComposite.java +++ b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/SourceViewerComposite.java @@ -225,8 +225,9 @@ public Point computeSize(int widthHint, int heightHint, boolean changed) { } Point textSize = textWidget.computeSize(widthHint, SWT.DEFAULT, changed); - int width = widthHint == SWT.DEFAULT ? textSize.x : widthHint; - int height = heightHint == SWT.DEFAULT ? getSourceViewerHeight(textWidget, textSize) : heightHint; + 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)); }