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

Add cursor support to DiabloUI and chat #6737

Merged
merged 1 commit into from
Oct 24, 2023
Merged

Conversation

glebm
Copy link
Collaborator

@glebm glebm commented Oct 23, 2023

Supports move left/right/home/end, backspace, delete, and Ctrl+V.

cursor-screencast.mp4

@glebm glebm marked this pull request as draft October 23, 2023 22:24
@glebm glebm changed the title Add cursor support to the DiabloUI text input Add cursor support to DiabloUI and chat Oct 23, 2023
@glebm glebm marked this pull request as ready for review October 23, 2023 22:57
@glebm glebm enabled auto-merge (rebase) October 23, 2023 23:00
@glebm glebm marked this pull request as draft October 23, 2023 23:03
auto-merge was automatically disabled October 23, 2023 23:03

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];
Copy link
Member

@qndel qndel Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exorcism-father-mulvehill

Copy link
Collaborator Author

@glebm glebm Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK so:

  1. This string literal is basically a static array.
  2. We can tell the length of a UTF-8 code point by looking at the first 4 bits of a leading code point.
  3. The array is a lookup table for all possible values of the first 4 bits. Values are code point lengths.

Copy link
Collaborator Author

@glebm glebm Oct 23, 2023

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).

Copy link
Member

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.
@glebm glebm marked this pull request as ready for review October 23, 2023 23:09
@glebm glebm enabled auto-merge (rebase) October 23, 2023 23:15
@FitzRoyX
Copy link

I've never felt constrained by just using backspace on short text strings. Not sure it's worth 250 extra lines of code.

@AJenbo
Copy link
Member

AJenbo commented Oct 24, 2023

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?

Copy link
Member

@AJenbo AJenbo left a 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 👍

@glebm glebm merged commit fdb5738 into diasurgical:master Oct 24, 2023
19 checks passed
@glebm glebm deleted the text-input branch October 24, 2023 06:41
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

Successfully merging this pull request may close these issues.

4 participants