JDK-8330590 : TextInputControl: previous word fails with Bhojpuri characters
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: jfx21
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2024-04-18
  • Updated: 2024-05-23
  • Resolved: 2024-05-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
jfx23 b19Fixed
Related Reports
Cloners :  
Relates :  
Relates :  
Description
Using Monkey Tester app (or a simple app that contains an editable TextArea or TextField), insert the following string:

"Bhojpuri 𑂦𑂷𑂔𑂣𑂳𑂩𑂲 test"

or using the unicode escapes

"Bhojpuri \ud804\udca6\ud804\udcb7\ud804\udc94\ud804\udca3\ud804\udcb3\ud804\udca9\ud804\udcb2 test"

- position the cursor at the end of text
- press Option+LEFT twice

Observed: the cursor first jumps to the beginning of the word 'test' then to the beginning of the word 'Bhojpuri'
Expected: the cursor should be positioned at the beginning of the word '𑂦𑂷𑂔𑂣𑂳𑂩𑂲'

The culprit is the code in TextInputControl:814 which calls Character.isLetterOrDigit(char) on a character which is a part of a surrogate pair instead of Character.isLetterOrDigit(int) on the code point.

The 'next word' function works correctly.

The issue is observed on macOS 14.4.1.

Added unit test in TextInputControlTest:

    @Test
    public void previousWord_Bhojpuri() {
        // "Bhojpuri \ud804\udca6\ud804\udcb7\ud804\udc94\ud804\udca3\ud804\udcb3\ud804\udca9\ud804\udcb2 test"
        textInput.setText("Bhojpuri 𑂦𑂷𑂔𑂣𑂳𑂩𑂲 test");
        textInput.end();
        verifyCaret(28);
        textInput.previousWord(); // at the beginning of "test"
        verifyCaret(24);
        textInput.previousWord(); // at the beginning of "𑂦𑂷𑂔𑂣𑂳𑂩𑂲"
        verifyCaret(9);
        textInput.previousWord(); // at the beginning of "Bhojpuri"
        verifyCaret(0);
    }
Comments
Changeset: b5fe3622 Author: Andy Goryachev <angorya@openjdk.org> Date: 2024-05-20 14:53:58 +0000 URL: https://git.openjdk.org/jfx/commit/b5fe362286056e516be1d26f5d1cdda12eb20a4c
20-05-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jfx/pull/1444 Date: 2024-04-19 19:44:28 +0000
19-04-2024

Possible fix might entail something similar to this change: https://github.com/andy-goryachev-oracle/jfx/commit/c70ada92b213e79231efecea3606c95d59f8887f
18-04-2024