We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4782

Summary: IME_SendEditingEvent() always calls SDL_SendEditingText() with incorrect arguments
Product: SDL Reporter: tamo <ttakah+sdl>
Component: eventsAssignee: Sam Lantinga <slouken>
Status: NEW --- QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2    
Version: HG 2.0   
Hardware: All   
OS: Windows 10   
Attachments: not "end" but "length", and fix "start" and "length"
fix scope
fix it with correct indent
fix header and indent
picture of IME composition

Description tamo 2019-09-01 19:32:58 UTC
First, see events/SDL_keyboard_c.h, line 56-57:

> /* Send editing text for selected range from start to end */
> extern int SDL_SendEditingText(const char *text, int start, int end);

But see video/windows/SDL_windowskeyboard.c, line 778:

>     SDL_SendEditingText(s, videodata->ime_cursor + (int)SDL_wcslen(videodata->ime_readingstring), 0);

The line should be:

>     SDL_SendEditingText(s, videodata->ime_cursor, (int)SDL_wcslen(videodata->ime_readingstring));

or

>     SDL_SendEditingText(s, len, (int)SDL_wcslen(videodata->ime_readingstring));

Otherwise, "start" and "end" are always incorrect.

--
Background: https://github.com/kivy/kivy/pull/6498
Comment 1 tamo 2019-09-01 20:02:50 UTC
Oops, "end" should be "len+wcslen(reading)".

> SDL_SendEditingText(s, len, len + (int)SDL_wcslen(videodata->ime_readingstring));
Comment 2 tamo 2019-09-01 20:15:29 UTC
No, reading events/SDL_keyboard.c and others, the last arg is not "end" but "length."
So events/SDL_keyboard.c is incorrect, too.
Comment 3 tamo 2019-09-01 20:24:24 UTC
Created attachment 3940 [details]
not "end" but "length", and fix "start" and "length"

Fix both header and code
Comment 4 tamo 2019-09-01 20:30:22 UTC
Created attachment 3941 [details]
fix scope

the previous patch didn't build
Comment 5 tamo 2019-09-01 20:32:21 UTC
Created attachment 3942 [details]
fix it with correct indent

fix indent
Comment 6 tamo 2019-09-02 07:31:09 UTC
Created attachment 3943 [details]
fix header and indent

The header is incorrect.
"readingstring" is just a pronunciation, not selection.

In fact, Japanese IMEs hardly use readingstring. (I've never imagined that.)
Comment 7 tamo 2019-09-02 07:42:42 UTC
Created attachment 3944 [details]
picture of IME composition

What I really wanted are, things like GetCompositionTargetRange and GetImeTextSpans in https://github.com/chromium/chromium/blob/master/ui/base/ime/win/imm32_manager.cc code.

So, at least two numbers should be given to the event: target_start and target_end.

See the attached picure.
The red range is the "target" and the yellow spans are "clauses" in IME terms.
The target range is necessary for Japanese. (That's what I thought "readingstring" was.)

Anyway, that's another issue.