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

nk_do_edit cut and copy handler passes len as grapheme cluster count to nk_plugin_copy not as count bytes in const char* #764

Open
klei1984 opened this issue Jan 24, 2025 · 0 comments

Comments

@klei1984
Copy link

Hello,
all demos handle the len parameter of the typedef void(*nk_plugin_copy)(nk_handle, const char*, int len); callback interface as number of bytes in a const char* null terminated C string excluding the nul terminator. But the cut & copy handler code snippet in nk_do_edit() actually passes the count grapheme clusters rendered.

            int b = edit->select_start;
            int e = edit->select_end;

            int begin = NK_MIN(b, e);
            int end = NK_MAX(b, e);
            text = nk_str_at_const(&edit->string, begin, &unicode, &glyph_len);
            if (edit->clip.copy)
                edit->clip.copy(edit->clip.userdata, text, end - begin);

In case of muti-byte encodings like utf-8 this leads to corrupted strings.

In case the nk_plugin_copy callback interface presents text as utf-8 encoded to the user, then the len parameter is currently wrongly set inside nk_do_edit(). In case len should represent glyph count, then multi-glyph or accented grapheme clusters are not supported.

In case it is guaranteed by design that nk_plugin_copy passes utf-8 encoded nul terminated string in its const char* anonymous parameter, then it is proposed to set len to number of bytes in the nul terminated string. In that case most of the existing demo backends would probably handle the len parameter correctly as most simply handle len as count bytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant