-
Notifications
You must be signed in to change notification settings - Fork 667
[CRITICAL] Fix clipboard text operations and UTF-8 cursor handling #841
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
base: master
Are you sure you want to change the base?
[CRITICAL] Fix clipboard text operations and UTF-8 cursor handling #841
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
|
Hi, @sleeptightAnsiC! 1 Cursor position issue state->cursor += len;it should be: state->cursor += glyphs;2 Clipboard copy bug - this one is mind-blowing edit->clip.copy(edit->clip.userdata, text, end - begin);The backend must provide its own implementation of this function. text = nk_str_at_const(&edit->string, begin, &unicode, &glyph_len);
text2 = nk_str_at_const(&edit->string, end, &unicode, &glyph_len);
if (edit->clip.copy)
edit->clip.copy(edit->clip.userdata, text, text2 - text);After these changes, everything starts working properly, though this is still just a draft fix. |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
The issues that I mentioned in #841 (comment) does not occur after 3342ffc But a possibility that you used LLM to fix those worries me a lot... |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as outdated.
This comment was marked as outdated.
|
Something is really odd here (and I'm not talking about LLM concerns anymore, although I think my concerns are valid) Per your comment under #852 (comment), if utf8/clipboard handling is broken everywhere (in every demo), this really feels like we have a regression here. What we should do first, is not trying to fix it, but instead we should find out why the regression has happened, what caused it and so on... Without this we may break something else, cause another regression, or run into risk that this thing will break again.
EDIT: Okey, fine... I think that the next Pavel's comment explains everything. Although, I still think this whole situation is a bit strange. |
|
@sleeptightAnsiC Lines 284 to 291 in fcd64f8
Here we clearly see that However, as I said earlier, all backends treat As for how old this issue is. It’s actually nearly 10 years old. I traced it back to the commit where version 1.0 was released. Before that point, Nuklear was still named zahnrad. |
ae86fca to
27ae085
Compare
|
@RobLoach I think this PR is finally ready to be merged! |
This comment was marked as outdated.
This comment was marked as outdated.
|
What in the ChatGPT 💀 ... I'll be happy to merge once we get the 👍 Any nit-picks can be fixed as follow ups. Thanks again, all, for all the hard work here. |
|
Given that this PR basically fixes something that was broken since forever, and I'm afraid a lot of people had to make some workarounds related to the bug, it might be safe to mark the fix as a "breaking change" and/or increase the major version (?) EDIT: after recent force-push the chenglog mentions about "POSSIBLE BREAKING CHANGE" so I think this one is solved (?) I'm definitely NOT someone who should be reviewing this. A long-time contributor should take an action here and decide. @rswinkle Would you mind taking a look? or maybe tag someone who you think is appropriate? |
I'm sorry, but the only real code change since that comment is just this small tweak: Everything else was just rebasing and updating the branch. |
This comment was marked as outdated.
This comment was marked as outdated.
|
Just to note, there have been a couple of previous attempts to address this:
This PR resolves the root cause. Personally, I believe it's obviously that the copy callback should take the number of bytes instead of glyphs. |
5f6aab0 to
61a0ae1
Compare
nk_str_insert_text_char when pasting UTF-8 text61a0ae1 to
5ad5e59
Compare
329fcd5 to
680cfca
Compare
2d12366 to
b3ac3ff
Compare
Changes: (1) length as byte count in copy callback (instead of glyph count) (2) fix nk_str_insert_text_char and nk_str_insert_str_char (3) correct UTF-8 cursor handling Fixes: Immediate-Mode-UI#840 Fixes: Immediate-Mode-UI#764 Obsoletes: Immediate-Mode-UI#543 BREAKING CHANGE: If your custom backed has a workaround for this issue, it will break.
e309902 to
255b63a
Compare
Co-authored-by: sleeptightAnsiC <91839286+sleeptightAnsiC@users.noreply.github.com>
255b63a to
5813fcb
Compare
|
Returning to this issue after some time: The more I think about it, the more I have a feeling this solution is the best one we will ever get. I'm still afraid about #841 (comment) a bit, but I don't have anything against merging it at this point. I've spoken quite a lot about this with Pavel via Discord DMs, and asked him for rebase and a little cleanup in the commits. This should now have a much cleaner changelog and description, and additional patch for workaround removal from demo/sdl3_renderer, so this PR is in way better shape right now. |
Edit: Improve structure
This pull request effectively repairs the entire clipboard handling system in Nuklear. To achieve this, it addresses three separate bugs:
nk_str_insert_text_charandnk_str_insert_str_charhas wrong implementation #840Note: see #840 for more details and a minimal reproducible example.