stb_textedit: Add support for custom move word left/right handlers #273
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
EDIT Minor edits applied since first posting.
Sorry to submit that right after you've done a bunch yesterday!
This patch allows the user to optionally define two functions to override ctrl-arrow style per-word movement,
STB_TEXTEDIT_MOVEWORDLEFT(obj,i)
andSTB_TEXTEDIT_MOVEWORDRIGHT(obj,i)
STB_TEXTEDIT_IS_SPACE(ch)
is still supported and will generate default handlers for those, matching the existing code.The reasoning is to allow applications to:
Minor notes:
STB_TEXTEDIT_IS_SPACE
with underscore should be called ``STB_TEXTEDIT_ISSPACE` to strictly be consistent with the other function names. It doesn't really matter, but that is why the new define don't have underscores.state->cursor-1
orstate->cursor+1
to the main key handling switch in textedit. Depending what you feel is best, the switch could passstate->cursor
to both those functions and leave it to the handlers to do -1/+1. It may actually make more sense like that! (just realizing this as I'm typing this message, I could amend the PR for that if you want)._arg
for function arguments instead ofarg
commonly used in the rest of the code. I haven't changed that to minimize the patch overhead but kept one argument namec
also to reduce the patch size and make it easier for you to parse it. I'm not sure if there was a reasoning for the extra underscore or if it came accidentally with another patch. While you are there you might want to rename the very few occurences of_str
tostr
to make the code more consistent.Thanks!