Skip to content

Conversation

@andy-goryachev-oracle
Copy link
Contributor

@andy-goryachev-oracle andy-goryachev-oracle commented Oct 16, 2025

Adds Input Method Editor (IME) support to RichTextArea/CodeArea.

Tested on macOS and Windows 11 with Japanese and Chinese (pinyin) input methods.
Please test this on Linux, even though there is no platform-specific code in this PR (should work the same way it does in TextArea/TextField)

For testing, one can use the updated Monkey Tester
https://github.com/andy-goryachev-oracle/MonkeyTest
(optionally enable IME events in stdout with Logging -> IME Monitor)

/reviewers 2


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8368478: RichTextArea: add IME support (Enhancement - P3)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1938/head:pull/1938
$ git checkout pull/1938

Update a local copy of the PR:
$ git checkout pull/1938
$ git pull https://git.openjdk.org/jfx.git pull/1938/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1938

View PR using the GUI difftool:
$ git pr show -t 1938

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1938.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 16, 2025

👋 Welcome back angorya! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Oct 16, 2025

@andy-goryachev-oracle This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8368478: RichTextArea: add IME support

Reviewed-by: kcr, kizune, lkostyra

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 1 new commit pushed to the master branch:

  • bf76ed2: 8370652: Control and ScrollPaneSkin should snap computed width/height values to prevent scrollbars appearing due to rounding errors

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk
Copy link

openjdk bot commented Oct 17, 2025

@andy-goryachev-oracle
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

@andy-goryachev-oracle andy-goryachev-oracle marked this pull request as ready for review October 17, 2025 23:11
@openjdk openjdk bot added the rfr Ready for review label Oct 17, 2025
@mlbridge
Copy link

mlbridge bot commented Oct 17, 2025

Webrevs

@kevinrushforth kevinrushforth self-requested a review October 20, 2025 18:25
@kevinrushforth
Copy link
Member

@lukostyra Can you also review?

Copy link
Contributor

@lukostyra lukostyra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I tested this on Windows with rich editor demo and using both polish and spanish IME shortcuts - all work fine after this change

@lukostyra
Copy link
Contributor

I tested this on Windows

I wrote this comment on Windows and something shorted in my brain when I was typing this. I meant on Linux, Ubuntu 24.04.2 :)

@andy-goryachev-oracle
Copy link
Contributor Author

andy-goryachev-oracle commented Oct 24, 2025

I am curious: could you tell me more about Polish/Spanish IME, what exactly have you try?
The reason I ask is (and I don't have much experience with European keyboards) is that these might go through the standard pathway, a regular keystroke.

The IME on the other hand, is a special UI that pops up with a list of candidates, and it's usually used with CJK languages:

Screenshot 2025-10-24 at 07 19 32

@beldenfox
Copy link
Contributor

On Mac and Linux dead key sequences are delivered as InputMethodEvents. When typing ü using dead keys the user previews the diacritic mark (¨) as composed text and then the final character (ü) is delivered as committed text.

@andy-goryachev-oracle
Copy link
Contributor Author

andy-goryachev-oracle commented Oct 24, 2025

Does it show any underline/dotted shapes? How do you type ü in German layout (on macOS)?

edit: Please disregard, I see it! Typing + or shift-+ (using the US keyboard) shows an IME composition shape.

@beldenfox
Copy link
Contributor

I usually test using a US keyboard and typing Option+e for ´ or Option+u for ¨ or Option+n for ˜

@lukostyra
Copy link
Contributor

I am curious: could you tell me more about Polish/Spanish IME, what exactly have you try?

As for Spanish, the method I use is to press ' key and then e key, that triggers an IME shortcut to input é. For Polish there is a few key combinations to get the diacritics, but since Poland most commonly uses the US keyboard layout its not always IME-dependent - I like to check them regardless though. The combos for Polish are Right Alt + A/C/E/L/N/O/X/Z - should produce ą/ć/ę/ł/ń/ó/ź/ż respectively. Note that these combos work only in layout sometimes (ex. on Windows) called "Polish (Programmers)", There's an older layout "Polish (214)" that dates all the way back to the typewriter era, but it's now considered obsolete and almost everyone uses the former.

One more IME check I also do borrows from this old commit replacing XIM with IBus and refers to Chinese (Pinyin) keyboard layout, simply trying to type "ni hao" - without IME this produces that exact text using latin alphabet, while with properly working IME it gets converted to respective Chinese characters.

In case of RTA, without this change Polish diacritics worked fine, but Spanish ones did not and Chinese keyboard produced latin characters. This change makes both the Spanish shortcut and Chinese character conversion work properly.

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works as expected on macOS (I'll try it on Windows later). I left a few comments, mostly about the line separator as it relates to the private getText(...) method in RichTextArea.

accessor = a;
}

public static boolean getText(RichTextArea t, TextPos start, TextPos end, StringBuilder sb, int limit, String lineSeparator) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the lineSeparator parameter really needed here? If not, I recommend removing it.

dy = f.snappedTopInset();

p = f.rangeShape(start, end);
p = f.rangeShape(start, end); // TODO new api, no null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this "TODO" really related to IME? If not, I recommend removing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code predates JDK-8357594
Additional geometry-based Text/TextFlow APIs. I am planning to migrate to the new API in a follow-up.

Created https://bugs.openjdk.org/browse/JDK-8370902

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for filing the RFE. Since you aren't otherwise modifying this method in this PR, adding a random TODO like this seems like an unrelated change. Now if you meant to also add this comment to line 232 (the call to f.getUnderlineShape(start, end) that you added above), then I could see also adding a reminder here as well.

So I recommend either adding a similar comment on line 232, or removing the unrelated TODOs.

* @param end the end position
* @param sb the buffer to copy to
* @param limit the maximum number of characters to copy, must be >= 0
* @param lineSeparator the newline separator sequence, or null to use the platform default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether and how to add lineSeparator is under review via PR #1944. I recommend removing everything related to line separators for this PR, unless you want this PR to be dependent on #1944.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and #1944 interrelated. Ideally, this PR should go first.

}

// while IME is active
static class Ime {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think can be private.

Comment on lines 1440 to 1442
* @since 26
*/
// TODO depends on JDK-8370140 (line separator property), private for now
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While a getText(...) method would be useful, I don't see an enhancement request that proposes it. I would make it more clear that this is not public API. If you want to leave the docs in place for a future enhancement that might provide such a public API, I recommend changing @since 26 to @since 99 (or similar).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, this is not a public API (yet).

first = false;
beg = start.offset();
} else {
sb.append(lineSeparator);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, should lineSeparator be hardcoded as "\n" or should it be the line.separator property? We often use \n regardless of which platform we are on unless we are writing to a file or doing something else where it matters. This is more a question for PR #1944, so whatever you do here will very likely be modified when that enhancement is implemented. Unless you want to make this PR dependent on that one, choose something now (other than passing it in as a method parameter, since that seems an unlikely choice) and add a comment that it will need to be revisited.

@azuev-java
Copy link
Member

I really want to test it on Linux - the IME there is quite fragile - and i will get back once i get my Linux box updated and running again. Should be done by the end of the week.

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Tested on Windows (in addition to macOS which I tested earlier).

I left a follow-up comment about your added TODOs. I'll reapprove if you make any changes.

dy = f.snappedTopInset();

p = f.rangeShape(start, end);
p = f.rangeShape(start, end); // TODO new api, no null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for filing the RFE. Since you aren't otherwise modifying this method in this PR, adding a random TODO like this seems like an unrelated change. Now if you meant to also add this comment to line 232 (the call to f.getUnderlineShape(start, end) that you added above), then I could see also adding a reminder here as well.

So I recommend either adding a similar comment on line 232, or removing the unrelated TODOs.

@andy-goryachev-oracle
Copy link
Contributor Author

Thank you for review!
I'd prefer to keep TODOs as they point to the areas that need improvement or further work.

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to keep TODOs as they point to the areas that need improvement or further work.

Then how about adding another TODO in the newly added method? That one is actually related to this PR, and is another place that (once this is integrated) you will want to change when you implement JDK-8370902.

dx = f.snappedLeftInset(); // TODO RTL?
dy = f.snappedTopInset();

p = f.getUnderlineShape(start, end);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
p = f.getUnderlineShape(start, end);
p = f.getUnderlineShape(start, end); // TODO new api

@azuev-java
Copy link
Member

I have tested couple of input methods including Japanese (Mozc) in different modes. In general the input method works and i was able to do the typing reasonably well but the editing sometimes leaves strange artifacts - especially when cancelling the suggestion - there is an underline text that was a raw input before suggestions and if you delete this text the underline stays but you can't navigate to that place as if there is no text but when window loses focus the raw input symbols re-appear in this place.

Also whenever i am trying to commit a suggestion the following warning pops in the terminal where i started the application:

(java:4993): IBUS-WARNING **: 15:31:22.791: ibus_input_context_post_process_key_event: Type 'h' is not supported.

Not sure what it is about.
I recorded the video that demonstrates the issue with the cancelled input but i do not think that this is a blocker for the feature.
Screencast from 2025-10-30 15-31-14.webm

@openjdk openjdk bot added the ready Ready to be integrated label Oct 30, 2025
@andy-goryachev-oracle
Copy link
Contributor Author

andy-goryachev-oracle commented Oct 30, 2025

Does it show the same artifacts with a regular TextArea?

The video does not seem to show the composition popup when the backspace (?) key presses happen.

On macOS, I noticed that Japanese IME works slightly different from Pinyin - you actually need to commit (or it thinks that it's still editing, I am not sure).

Also, you can try enabling the Logging -> IME Monitor in the latest monkey tester and see what linux IME generates - on macOS, I could not do left arrow while in IME, and backspace simply removes the character and the dotted line underneath it. Could it be some bug in IME/Linux?

The latest monkey tester:
https://github.com/andy-goryachev-oracle/MonkeyTest

@andy-goryachev-oracle
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Oct 31, 2025

Going to push as commit 5d06943.
Since your change was applied there have been 2 commits pushed to the master branch:

  • ef387fc: 8370235: WebKit build fails on Windows 32-bit and Linux 32-bit after JDK-8367578
  • bf76ed2: 8370652: Control and ScrollPaneSkin should snap computed width/height values to prevent scrollbars appearing due to rounding errors

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Oct 31, 2025
@openjdk openjdk bot closed this Oct 31, 2025
@openjdk openjdk bot removed ready Ready to be integrated rfr Ready for review labels Oct 31, 2025
@openjdk
Copy link

openjdk bot commented Oct 31, 2025

@andy-goryachev-oracle Pushed as commit 5d06943.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@andy-goryachev-oracle andy-goryachev-oracle deleted the 8368478.ime branch October 31, 2025 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

5 participants