On Tue, 6 Jan 2026 17:08:33 GMT, Andy Goryachev <[email protected]> wrote:

>> # Use Case
>> 
>> typing into RichTextArea with a default model (or any other model that 
>> supports discrete styles), in the presence of a tool bar or similar UI that 
>> allows to specify the styles to take effect on the next key press.  Example:
>> - open MS Word or another rich text editor such as TextEdit
>> - type something
>> - place cursor at the middle of the typed text and hit command-B or ctrl-B 
>> on Win/Linux
>> - notice how the formatting toolbar highlights [b] button indicating that 
>> the style for next character to be inserted has changed to bold
>> - type something and confirm that inserted text is bold
>> the new style is captured only in the toolbar UI, so clicking on some other 
>> part of the text reverts the bold button to the unselected state.
>> 
>> 
>> # Problem
>>  
>> typing a character uses the model's logic to deal with the styles, via 
>> StyledTextModel::replace(StyleResolver resolver, TextPos start, TextPos end, 
>> String text) method, see RichTextAreaBehavior::handleTypedChar().  This 
>> worked well initially, however it makes it impossible (without extending 
>> RichTextAreaBehavior which is not a public class) to implement the behavior 
>> described earlier.
>> 
>> 
>> # Solution
>> 
>> - add 'insertStyles<StyleAttributeMap>' property to the RichTextArea, which 
>> will override the model styles in RichTextAreaBehavior::handleTypedChar() if 
>> the value is not null
>
> Andy Goryachev has updated the pull request with a new target base due to a 
> merge or a rebase. The incremental webrev excludes the unrelated changes 
> brought in by the merge/rebase. The pull request contains seven additional 
> commits since the last revision:
> 
>  - 2026
>  - Merge branch 'master' into 8374035.insert.styles
>  - test
>  - 26
>  - Merge branch 'master' into 8374035.insert.styles
>  - Merge branch 'master' into 8374035.insert.styles
>  - insert styles

The new API looks good. I left a comment about the docs (and also a question 
about the new test) inline.

modules/jfx.incubator.richtext/src/main/java/jfx/incubator/scene/control/richtext/RichTextArea.java
 line 600:

> 598:     /**
> 599:      * Specifies the styles to be in effect for the characters to be 
> inserted via user input.
> 600:      * The value can be null.

Can you document the behavior when this is null? Looking at the implementation, 
I think it takes the style at the caret position, but would be helpful to 
specify (also say whether there is a different depending on whether the caret 
is leading or trailing).

modules/jfx.incubator.richtext/src/test/java/test/jfx/incubator/scene/control/richtext/RichTextAreaTest.java
 line 586:

> 584:         assertEquals(BOLD, control.getActiveStyleAttributeMap());
> 585:         control.select(TextPos.ofLeading(0, 6));
> 586:         assertEquals(ITALIC, control.getActiveStyleAttributeMap());

Maybe also test that setting it to `null` does what you expect (uses the style 
at the cursor I presume)?

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

PR Review: https://git.openjdk.org/jfx/pull/2017#pullrequestreview-3632188693
PR Review Comment: https://git.openjdk.org/jfx/pull/2017#discussion_r2666027494
PR Review Comment: https://git.openjdk.org/jfx/pull/2017#discussion_r2666042191

Reply via email to