From d72c73ab2fca58a707bd032d1d321db34541fde1 Mon Sep 17 00:00:00 2001 From: Patrick Hemmer Date: Tue, 21 Oct 2025 07:02:56 -0400 Subject: [PATCH] fix: backtick code overflowing and going out of view (#1145) Previously when text was enclosed in backticks, that text wouldn't wrap, and would instead overflow beyond the viewport. In addition, there is no horizontal scroll bar, so the text is completely inaccessible. And to make it even worse, because of this, the virtual viewport was extended, causing other non-backtick text to also go out of view. This fixes the issue by overriding the style to enable wrapping. --- src/main/java/ee/carlrobert/codegpt/ui/UIUtil.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/ee/carlrobert/codegpt/ui/UIUtil.java b/src/main/java/ee/carlrobert/codegpt/ui/UIUtil.java index de4ed280..657e5db9 100644 --- a/src/main/java/ee/carlrobert/codegpt/ui/UIUtil.java +++ b/src/main/java/ee/carlrobert/codegpt/ui/UIUtil.java @@ -44,6 +44,8 @@ import javax.swing.KeyStroke; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; import javax.swing.text.DefaultCaret; +import javax.swing.text.html.HTMLEditorKit; +import javax.swing.text.html.StyleSheet; public class UIUtil { @@ -60,7 +62,10 @@ public class UIUtil { public static JTextPane createTextPane(String text, boolean opaque, HyperlinkListener listener) { var textPane = new JTextPane(); textPane.putClientProperty(JTextPane.HONOR_DISPLAY_PROPERTIES, true); - textPane.setEditorKit(HTMLEditorKitBuilder.simple()); + var editorKit = new HTMLEditorKitBuilder().withWordWrapViewFactory().build(); + StyleSheet styleSheet = editorKit.getStyleSheet(); + styleSheet.addRule("code { white-space: pre-wrap; word-wrap: break-word; }"); + textPane.setEditorKit(editorKit); textPane.addHyperlinkListener(listener); textPane.setContentType("text/html"); textPane.setEditable(false);