Skip to content

Conversation

gqw
Copy link

@gqw gqw commented Nov 10, 2020

This PR want fix a bug about InputText callback:

In InputText callback I want translate chinese pinyin 'hao' to '好', before callback 'hao' length is 3,
after callback '好''s utf-8 length is 3 too. So ImTextCountCharsFromUtf8 was ignored, that's not right.
Anyway, ImTextCountCharsFromUtf8 should be called to calculate real length.

@ocornut
Copy link
Owner

ocornut commented Nov 10, 2020

The code you changed doesn’t calculate text length. Please provide a repro of your actual issue and make sure your callback function sets the dirty flag in the callback data buffer.

@ocornut
Copy link
Owner

ocornut commented Nov 10, 2020 via email

@gqw
Copy link
Author

gqw commented Nov 10, 2020

Yes, it should be like this:

if (callback_data.CursorPos != utf8_cursor_pos || callback_data.BufDirty) { state->Stb.cursor = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.CursorPos); state->CursorFollow = true; }

@gqw
Copy link
Author

gqw commented Nov 10, 2020

I don't think we need add all three checks, but only the first one.

@ocornut ocornut added the bug label Nov 11, 2020
@ocornut
Copy link
Owner

ocornut commented Nov 11, 2020

I don't think we need add all three checks, but only the first one.

The Selection fields are also position will would be affected by the same UTF-8<>wchar count transition.

Thank you, will merge this soon.

In InputText callback I want translate chinese pinyin 'hao' to '好',

By the way, the https://github.com/ocornut/imgui/wiki/Useful-Widgets page is listing this project:
https://github.com/maildrop/DearImGui-with-IMM32
May be useful to you. I think this could be reworked to become a separate library.

ocornut pushed a commit that referenced this pull request Nov 11, 2020
…lters the buffer in a way where the byte count is unchanged but the decoded character count changes. (#3587)
@ocornut
Copy link
Owner

ocornut commented Nov 11, 2020

Merged.

@ocornut ocornut closed this Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants