On Fri, 2 Oct 2026 05:31:17 GMT, Robert Lichtenberger <[email protected]> 
wrote:

>> As analysed in the bug, the previousWord() method does not work correctly if 
>> at the word boundary a character is found that is neither letter nor digit.
>> This fix changes the method so that only ranges of whitespace will be 
>> skipped, resulting in correct word selection behaviour.
>> A test case has been added to TextAreaTest.
>> gradlew :controls:test --tests test.javafx.scene.control.Text*Test has been 
>> executed to ensure no regressions happen in other text related classes. No 
>> errors were reported.
>> 
>> 
>> ---------
>> - [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 one 
> additional commit since the last revision:
> 
>   8264588: Remove extra newline, Put @Test annotation on separate line.

I've played around a bit so that the 
`com.sun.javafx.scene.control.behavior.TextAreaBehavior#mouseDoubleClick` can 
really be tested, like this:

    @Test
    public void testDoubleClick() {
        execute(
                setText("Bug #123"),
                clickCharacter(0, 2)
        );
        Assertions.assertEquals("Bug", control.getSelectedText());

        execute(
                clickCharacter(6, 2)
        );
        Assertions.assertEquals("#123", control.getSelectedText());

        execute(
                setText("aaa bbb"),
                clickCharacter(4, 2)
        );
        Assertions.assertEquals("bbb", control.getSelectedText());
    }

The clickCharacter method lives in `TextInputControlTestBase` and looks like 
this:

    protected Runnable clickCharacter(int index, int clickCount) {
        return () -> {
            Rectangle2D bounds = ((TextInputControlSkin<?>) 
control.getSkin()).getCharacterBounds(index);
            ;
            MouseEventFirer mouse = new MouseEventFirer(control);
            for (int i = 1; i <= clickCount; i++) {
                mouse.fireMousePressAndRelease(i, bounds.getMinX() - 
control.getLayoutBounds().getWidth() / 2, bounds.getMinY() - 
control.getLayoutBounds().getHeight() / 2);
            }
        };
    }


The last of the above tests (double clicking on the first b of "aaa bbb") 
currently fails, because of the way `mouseDoubleClick` works: First go to the 
previous word (which is "aaa", because the first click will set the caret in 
front of bbb), then select the next word.

To fix this would require changing mouseDoubleClick in a more profound way, 
e.g. the way I "specified" above.

However I am unsure whether this should still be part of this Issue/PR.

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

PR Comment: https://git.openjdk.org/jfx/pull/2334#issuecomment-5948582646

Reply via email to