Desktop: wrap long links instead of scrolling the chat sideways

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-02 08:34:30 +00:00
co-authored by Claude Opus 5.5
parent c3a4a0658e
commit 047ad1c1b9
@@ -16,6 +16,7 @@ import javax.swing.text.Element;
import javax.swing.text.View;
import javax.swing.text.ViewFactory;
import javax.swing.text.html.ImageView;
import javax.swing.text.html.InlineView;
import javax.swing.text.html.StyleSheet;
import java.awt.Color;
import java.awt.Font;
@@ -152,7 +153,9 @@ public final class HtmlStyles {
@Override
public View create(Element elem) {
View view = super.create(elem);
return view instanceof ImageView ? new ZoomedImageView(elem) : view;
if (view instanceof ImageView) return new ZoomedImageView(elem);
if (view instanceof InlineView) return new WrappingInlineView(elem);
return view;
}
};
@@ -178,6 +181,22 @@ public final class HtmlStyles {
}
}
/**
* Text that may break anywhere once it has no space left to break at: by default the
* longest word (typically a link) is the pane's minimum width, and a scroll pane then
* scrolls sideways instead of wrapping it.
*/
private static final class WrappingInlineView extends InlineView {
WrappingInlineView(Element elem) {
super(elem);
}
@Override
public float getMinimumSpan(int axis) {
return axis == X_AXIS ? 0 : super.getMinimumSpan(axis);
}
}
private static final class ZoomedImageView extends ImageView {
ZoomedImageView(Element elem) {
super(elem);