-
Notifications
You must be signed in to change notification settings - Fork 654
[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 (?) 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. |
Retested and everything seems fine.
My only nitpick here is that it might be nice to have this change as one single commit (?) Those two commits don't really work correctly without each other, and the third commit is rebuilding the amalgamation, so it may confuse people. This way, if said change ever causes an issue for someone, it will be easier to find it with git-log or git-bisect. But this is just a minor inconvenience, and @RobLoach can easily solve it with "squash+merge", so no worries. And my previous comment still applies #841 (comment) |
|
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 textChanges: (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.
61a0ae1 to
5ad5e59
Compare
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.