-
Notifications
You must be signed in to change notification settings - Fork 810
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
Add cursor support to DiabloUI and chat #6737
Conversation
Pull request was converted to draft
*/ | ||
inline size_t Utf8CodePointLen(const char *src) | ||
{ | ||
return "\1\1\1\1\1\1\1\1\1\1\1\1\2\2\3\4"[static_cast<unsigned char>(*src) >> 4]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK so:
- This string literal is basically a static array.
- We can tell the length of a UTF-8 code point by looking at the first 4 bits of a leading code point.
- The array is a lookup table for all possible values of the first 4 bits. Values are code point lengths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compilers don't seem to handle constexpr
arrays as well as string literals in some scenarios yet. See for example:
fmtlib/fmt@06b2038
It's just as readable in a string as it would be in an array though (not very).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, i think I get it now, since I know some basic UTF8
Supports move left/right/home/end, backspace, delete, and Ctrl+V.
I've never felt constrained by just using backspace on short text strings. Not sure it's worth 250 extra lines of code. |
If he strips out all the documentation and abstraction and any blank lines would it then be worth it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice with a good abstraction for handling text input in general 👍
Supports move left/right/home/end, backspace, delete, and Ctrl+V.
cursor-screencast.mp4