Skip to content

Commit be3e58b

Browse files
CopilotMte90
andcommitted
Improve width handling: enhance WrappingEditorPane and set messagePanel max width
Co-authored-by: Mte90 <403283+Mte90@users.noreply.github.com>
1 parent 4da3559 commit be3e58b

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

ide-plugins/src/main/kotlin/com/picocode/PicoCodeToolWindowContent.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,28 @@ class WrappingEditorPane : JEditorPane() {
2323
override fun getScrollableTracksViewportWidth(): Boolean = true
2424

2525
override fun getPreferredSize(): Dimension {
26-
// Ensure the preferred width doesn't exceed the parent's width
26+
// Let the parent determine the width, we only care about height
2727
val preferredSize = super.getPreferredSize()
28+
29+
// If we're in a scroll pane, use the viewport width
2830
val parent = parent
29-
if (parent != null && parent.width > 0) {
30-
preferredSize.width = parent.width
31+
if (parent is JViewport) {
32+
val viewportWidth = parent.width
33+
if (viewportWidth > 0) {
34+
// Set a temporary size to calculate the proper height
35+
setSize(viewportWidth, Int.MAX_VALUE)
36+
preferredSize.width = viewportWidth
37+
preferredSize.height = super.getPreferredSize().height
38+
}
3139
}
3240
return preferredSize
3341
}
42+
43+
override fun getMaximumSize(): Dimension {
44+
val maxSize = super.getMaximumSize()
45+
maxSize.width = Integer.MAX_VALUE
46+
return maxSize
47+
}
3448
}
3549

3650
/**
@@ -259,6 +273,9 @@ class PicoCodeToolWindowContent(private val project: Project) {
259273
for ((index, msg) in chatHistory.withIndex()) {
260274
val messagePanel = JPanel(BorderLayout())
261275

276+
// Ensure messagePanel respects the container width
277+
messagePanel.maximumSize = Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)
278+
262279
// Use theme-aware colors
263280
val borderColor = if (msg.sender == "You")
264281
JBColor.BLUE

0 commit comments

Comments
 (0)