On Fri, 10 Jul 2026 19:11:28 GMT, Andy Goryachev <[email protected]> wrote:

>> # Support for Embedded Images, Text Highlights, Wavy Underlines
>> 
>> ## Summary
>> 
>> This PR adds new attributes to support embedded images, text highlights, and 
>> wavy underlines.
>> 
>> The `RichEditorDemoApp` gains new context menus and enables drag and drop to 
>> showcase the new functionality.
>> 
>> <img width="768" height="703" alt="Screenshot 2026-06-18 at 12 40 28" 
>> src="https://github.com/user-attachments/assets/678bdbac-6582-46ee-bd41-ea938df930bb";
>>  />
>> 
>> 
>> 
>> ## Problem
>> 
>> Among the feedback received after publishing the RichTextArea incubating 
>> module, a number of users complained about the need to support embedded 
>> images.  Other users complained about difficulty to get the text highlighted 
>> or wavy underlined, and having these decorations controlled via CSS.
>> 
>> 
>> ## Solution
>> 
>> Support for images was intentionally missing in the initial release; this PR 
>> adds the feature.
>> 
>> Adding highlights and underlines is a bit more complicated, for several 
>> reasons.  One reason is that the existing highlighting mechanism supports 
>> mixing of arbitrary number of translucent colors - something that is pretty 
>> much impossible to do with CSS alone.
>> 
>> A useful compromise is to offer a limited number of standard attributes that 
>> can be controlled via CSS: 5 highlights and 3 wavy underlines.
>> 
>> 
>> ## Specification
>> 
>> 
>> ### StyleAttributeMap Attributes
>> 
>> New attributes:
>> - EMBEDDED_IMAGE
>> - TEXT_HIGHLIGHT_1 ... TEXT_HIGHLIGHT_5
>> - UNDERLINE_WAVY_1 ... UNDERLINE_WAVY_3
>> 
>> ### CSS Styling
>> 
>> The styling of highlights and wavy underlines is determined by the 
>> stylesheet and can be changed by the user.
>> 
>> The style selectors are:
>> 
>> `.rich-text-area .text-highlight-1` ... `.rich-text-area .text-highlight-5`
>> `.rich-text-area .underline-wavy-1` ... `.rich-text-area .underline-wavy-3`
>> 
>> 
>> ### New Public APIs
>> 
>> `EmbeddedImage`
>> `FileListFormatHandler`
>> `StyleAttribute.inlineNode()`
>> `StyleAttribute.isInlineNode()`
>> `StyledSegment.ofInlineNode()`
>> `CellContext.RunDecor`
>> `CellContext.decorateRun()`
>> `RichTextArea.dropTargetProperty`
>> `RichTextArea.clearDropTarget()`
>> `RichTextArea.getStyleAttributeMap()`
>> 
>> 
>> ### File Format Changes
>> 
>> The data transfer format (also used by the demo app to save the .rich files) 
>> version string is changed, making the old files unreadable (no backward 
>> compatibility will be provided during incubation period).
>> 
>> 
>> ### Breaking API Changes
>> 
>> `DataFormatHandler.createStyledInput()`
>> `StyledTextMod...
>
> Andy Goryachev has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   closing )

I reviewed most of the the code changes and didn't spot anything else. I did 
leave a couple minor formatting issues inline.

I ran the RTA editor demo, and tried both a copy/paste and a drag/drop of an 
image, but nothing happened. What am I doing wrong?

Other things I noticed:

If I highlight text and type in the middle of it, it doesn't apply the 
highlight to the inserted text. Character styles work as expected. Is this 
intentional?

A few follow-up Enhancements that seem worth considering:

1. Add another EmbeddedImage factory method that takes a URL

2. Store / read the mime type as part of the native RTA output format

3. Consider another EmbeddedImage factory method that takes an 
already-constructed Image. This might be a bit tricky when it comes to writing 
it: you would either need to encode it, e.g., to a lossless PNG format, or come 
up with a "raw" format that stores the raw image data and enough metadata to 
allow it to be decoded. This may or may not be worth it.

apps/samples/RichTextAreaDemo/src/com/oracle/demo/richtext/rta/DemoModel.java 
line 57:

> 55:         set(StyleAttributeMap.TEXT_HIGHLIGHT_1, Boolean.TRUE).
> 56:         setFontSize(16).
> 57:         build();

Minor suggestion: the usual pattern for multi-line fluent calls (e.g., 
builders, streams) is to put the `.` on the same line as the method.


Suggestion:

    private static final StyleAttributeMap OVERLAP1 = 
StyleAttributeMap.builder()
        .set(StyleAttributeMap.TEXT_HIGHLIGHT_1, Boolean.TRUE)
        .setFontSize(16)
        .build();

modules/jfx.incubator.richtext/src/main/java/com/sun/jfx/incubator/scene/control/richtext/TextCell.java
 line 567:

> 565:         private int lastCount;
> 566:         private final ArrayList<DecorationRun> runs = new ArrayList<>(4);
> 567:         private HashMap<StyleAttribute<?>,DecorationRun> byType = new 
> HashMap<>();

Minor: missing space after `,`

modules/jfx.incubator.richtext/src/main/java/com/sun/jfx/incubator/scene/control/richtext/TextCell.java
 line 581:

> 579:                 if (n instanceof Text t) {
> 580:                     offset += t.getText().length();
> 581:                 } else if(n.isManaged()) { // ignoring highlights added 
> in VFlow:824

Minor: missing space after `if`

modules/jfx.incubator.richtext/src/main/java/com/sun/jfx/incubator/scene/control/richtext/util/RichUtils.java
 line 186:

> 184:             if (n instanceof Text t) {
> 185:                 len += t.getText().length();
> 186:             } else if(n.isManaged()) {

Minor: missing space after `if`.

-------------

PR Review: https://git.openjdk.org/jfx/pull/2196#pullrequestreview-4694171551
PR Review Comment: https://git.openjdk.org/jfx/pull/2196#discussion_r3578898797
PR Review Comment: https://git.openjdk.org/jfx/pull/2196#discussion_r3579062046
PR Review Comment: https://git.openjdk.org/jfx/pull/2196#discussion_r3578883795
PR Review Comment: https://git.openjdk.org/jfx/pull/2196#discussion_r3579033182

Reply via email to