Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IME: TextEdit widget cannot support CompositionEnd only input character #3766

Closed
FrankLeeC opened this issue Jan 4, 2024 · 5 comments · Fixed by #3768
Closed

IME: TextEdit widget cannot support CompositionEnd only input character #3766

FrankLeeC opened this issue Jan 4, 2024 · 5 comments · Fixed by #3768
Labels
bug Something is broken eframe Relates to epi and eframe egui-winit porblems related to winit

Comments

@FrankLeeC
Copy link
Contributor

FrankLeeC commented Jan 4, 2024

Describe the bug
Can not input CompositionEnd character directly into TextEditor.
when input no-latin character such as Chinese into TextEditor, i must first input some word to trigger CompositionStart/CompositionUpdate event, then input some mark to trigger CompositionEnd event.
if i just want to type in a single character that trigger CompositionEnd event, TextEditor won't insert this character to text.

image

To Reproduce
1.Setup a demo app containing a TextEdit
2.Use Chinese PinYin input.
3.Do not type in any other word, just press [shift+1] , [shift+6] , [,], [.], [?] or any other CompositionEnd character.
4.Nothing typed into TextEdit

Expected behavior
Expected to type in Chinese character directly such as !……,。《》、【】without need to trigger CompositionStart/CompositionUpdate event.

Desktop (please complete the following information):
 - OS: Windows11 Naive
 - Browser Naive App
 - Version 0.24.1 and master branch

/crates/egui/src/widgets/text_edit/builder.rs L1061.
if prediction != "\n" && prediction != "\r" && state.has_ime
this line ensure that i cannot input any CompositionEnd character unless input something to trigger CompositionStart to make has_ime as true.
tried to modify this line to
if prediction != "\n" && prediction != "\r"
if don't ensure has_ime be true, input CompositionEnd character directly successfully. Also, following some CompositionStart/CompositionUpdate character works too.
image

@FrankLeeC FrankLeeC added the bug Something is broken label Jan 4, 2024
@emilk emilk changed the title TextEdit widget cannot support CompositionEnd only input character IME: TextEdit widget cannot support CompositionEnd only input character Jan 4, 2024
@emilk emilk added eframe Relates to epi and eframe egui-winit porblems related to winit labels Jan 4, 2024
@emilk
Copy link
Owner

emilk commented Jan 4, 2024

Can you check if window.set_ime_allowed is called at the correct time in crates/egui-winit/src/lib.rs?

@FrankLeeC
Copy link
Contributor Author

FrankLeeC commented Jan 4, 2024

Can you check if window.set_ime_allowed is called at the correct time in crates/egui-winit/src/lib.rs?

add log after L731(if self.allow_ime != allow_ime) in crates/egui-winit/src/lib.rs
when mouse focus in textedit, window.set_ime_allowed is called, allow_time is true and self.allow_time is false.
when mouse focus outside textedit,
called again, allow_time is false and self.allow_time is true.

@emilk
Copy link
Owner

emilk commented Jan 4, 2024

Ok, so that at least seems to work.

So as far as I understand you, you see CompositionEnd events with the correct characters ( etc), and though the TextEdit has focus and set_ime_allowed(true), the characters don't show up in the TextEdit field?

It looks to me the use of state.has_ime in crates/egui/src/widgets/text_edit/builder.rs may be wrong.

Since you seem to know how IME should work (I don't 😅), could you please take a look, and perhaps make a PR if you figure out a fix? 🙏

@FrankLeeC
Copy link
Contributor Author

Ok, so that at least seems to work.

So as far as I understand you, you see CompositionEnd events with the correct characters ( etc), and though the TextEdit has focus and set_ime_allowed(true), the characters don't show up in the TextEdit field?

It looks to me the use of state.has_ime in crates/egui/src/widgets/text_edit/builder.rs may be wrong.

Since you seem to know how IME should work (I don't 😅), could you please take a look, and perhaps make a PR if you figure out a fix? 🙏

Thank you for your help. I'll make a PR later.😀

@FrankLeeC
Copy link
Contributor Author

Here is a PR for this bugfix. #3768

emilk added a commit that referenced this issue Jan 4, 2024
* Closes #3766

Add support for type in CompositionEnd only characters without trigger
CompositionStart first.
This usually works with no-latin character input.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken eframe Relates to epi and eframe egui-winit porblems related to winit
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants