On Mon, 9 Nov 2026 13:59:11 GMT, Robert Lichtenberger <[email protected]> 
wrote:

>> This patch provides a minimal solution to JDK-8393470 [TextInputControl] 
>> double click on leading char selects wrong word.
>> It simply checks if the caret is already at the start of a word and in that 
>> case it prevents the jumping to the start of the previous word.
>> 
>> It takes the one scenario from testDoubleClickSelectsCharacterClassBlocks 
>> that is fixed by the patch and moves it into a separate test method.
>> 
>> The other scenarios from testDoubleClickSelectsCharacterClassBlocks are 
>> removed, since they cannot be achieved without changing a lot of behavior 
>> and the current behavior while not being _my_ favorite way can be argued as 
>> "correct" in the absence of a formal specification.
>> 
>> 
>> ---------
>> - [X] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Robert Lichtenberger has updated the pull request incrementally with two 
> additional commits since the last revision:
> 
>  - Update 
> modules/javafx.controls/src/main/java/com/sun/javafx/scene/control/behavior/TextAreaBehavior.java
>    
>    Co-authored-by: Marius Hanl <[email protected]>
>  - Update 
> modules/javafx.controls/src/main/java/com/sun/javafx/scene/control/behavior/TextAreaBehavior.java
>    
>    Co-authored-by: Marius Hanl <[email protected]>

Well, you are right about keeping the existing behavior for the sake of 
backward compatibility, thought I would add one point - unless the current 
behavior is clearly incorrect.

I think even MS Word revised its approach to navigation, selection, and editing 
in the past years, so I think we could (and maybe should) update JavaFX 
handling of the text input components as well.  Maybe even make it work similar 
to MS Word, a de-facto standard?  Though it is out of scope for this PR :-)

Speaking of BreakIterators - please be aware that we might encounter combining 
unicode symbols, surrogates, or even grapheme clusters (which we currently 
don't render correctly).

modules/javafx.controls/src/main/java/com/sun/javafx/scene/control/behavior/TextAreaBehavior.java
 line 405:

> 403:     protected void mouseDoubleClick(HitInfo hit) {
> 404:         final TextArea textArea = getNode();
> 405:         if (!isAtWordStart(textArea)) {

should the same fix be applied to the `TextField`?

modules/javafx.controls/src/main/java/com/sun/javafx/scene/control/behavior/TextAreaBehavior.java
 line 422:

> 420:         } else if (pos < textArea.getLength()) {
> 421:             String text = textArea.getText();
> 422:             atWordStart = Character.isWhitespace(text.charAt(pos - 1)) 
> && !Character.isWhitespace(text.charAt(pos));

there are a few whitespace chars that Character.isWhitespace() return false:


NEXT_LINE \u0085
NO_BREAK_SPACE \u00a0
FIGURE_SPACE \u2007
NARROW_NO_BREAK_SPACE \u202f


the no-break space chars we probably shouldn't consider as breaking;
`NEXT_LINE` - having this in TextInputControl makes no sense
but what about `FIGURE_SPACE` ?

or should we use `Character.isWhitespace() || Character.isSpaceChar()` ?

modules/javafx.controls/src/test/java/test/javafx/scene/control/behavior/TextAreaBehaviorTest.java
 line 151:

> 149:     @Test
> 150:     @Disabled("JDK-8393470")
> 151:     public void testDoubleClickSelectsCharacterClassBlocks() {

should we add the fixed cases?  including the pos=0 one?

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

PR Review: https://git.openjdk.org/jfx/pull/2363#pullrequestreview-5831673187
PR Review Comment: https://git.openjdk.org/jfx/pull/2363#discussion_r4517167809
PR Review Comment: https://git.openjdk.org/jfx/pull/2363#discussion_r4517457133
PR Review Comment: https://git.openjdk.org/jfx/pull/2363#discussion_r4517289550

Reply via email to