Skip to content

Commit 4da3559

Browse files
CopilotMte90
andcommitted
Add word-wrapping CSS to prevent horizontal overflow in chat messages
Co-authored-by: Mte90 <403283+Mte90@users.noreply.github.com>
1 parent 5a4a4a6 commit 4da3559

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ import com.google.gson.JsonArray
2121
*/
2222
class WrappingEditorPane : JEditorPane() {
2323
override fun getScrollableTracksViewportWidth(): Boolean = true
24+
25+
override fun getPreferredSize(): Dimension {
26+
// Ensure the preferred width doesn't exceed the parent's width
27+
val preferredSize = super.getPreferredSize()
28+
val parent = parent
29+
if (parent != null && parent.width > 0) {
30+
preferredSize.width = parent.width
31+
}
32+
return preferredSize
33+
}
2434
}
2535

2636
/**
@@ -212,24 +222,24 @@ class PicoCodeToolWindowContent(private val project: Project) {
212222
.replace(Regex("^- (.+)$", RegexOption.MULTILINE), "<li>$1</li>")
213223
.replace(Regex("^\\* (.+)$", RegexOption.MULTILINE), "<li>$1</li>")
214224

215-
// Restore code blocks with proper styling
225+
// Restore code blocks with proper styling and wrapping
216226
codeBlockPlaceholders.forEachIndexed { index, content ->
217227
val escapedContent = content
218228
.replace("&", "&amp;")
219229
.replace("<", "&lt;")
220230
.replace(">", "&gt;")
221231
html = html.replace("###CODEBLOCK${index}###",
222-
"<pre style='background-color: rgba(127, 127, 127, 0.1); padding: 8px; border-radius: 4px; overflow-x: auto; border: 1px solid rgba(127, 127, 127, 0.2);'><code>$escapedContent</code></pre>")
232+
"<pre style='background-color: rgba(127, 127, 127, 0.1); padding: 8px; border-radius: 4px; border: 1px solid rgba(127, 127, 127, 0.2); white-space: pre-wrap; word-wrap: break-word; overflow-wrap: break-word;'><code>$escapedContent</code></pre>")
223233
}
224234

225-
// Restore inline code with proper styling
235+
// Restore inline code with proper styling and wrapping
226236
inlineCodePlaceholders.forEachIndexed { index, content ->
227237
val escapedContent = content
228238
.replace("&", "&amp;")
229239
.replace("<", "&lt;")
230240
.replace(">", "&gt;")
231241
html = html.replace("###INLINECODE${index}###",
232-
"<code style='background-color: rgba(127, 127, 127, 0.15); padding: 2px 4px; border-radius: 3px;'>$escapedContent</code>")
242+
"<code style='background-color: rgba(127, 127, 127, 0.15); padding: 2px 4px; border-radius: 3px; word-wrap: break-word; overflow-wrap: break-word;'>$escapedContent</code>")
233243
}
234244

235245
// Wrap consecutive list items in <ul> tags
@@ -240,7 +250,7 @@ class PicoCodeToolWindowContent(private val project: Project) {
240250
// Convert line breaks (but not inside pre/code tags)
241251
html = html.replace("\n", "<br/>")
242252

243-
return "<html><body style='font-family: sans-serif; font-size: 11px; width: 100%;'>$html</body></html>"
253+
return "<html><body style='font-family: sans-serif; font-size: 11px; width: 100%; word-wrap: break-word; overflow-wrap: break-word;'>$html</body></html>"
244254
}
245255

246256
private fun renderChatHistory() {

0 commit comments

Comments
 (0)