-
-
Notifications
You must be signed in to change notification settings - Fork 101
EditBox: Add onCaretPositionChange Signal and Fix Bugs in EditBox::selectText() #206
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
EditBox: Add onCaretPositionChange Signal and Fix Bugs in EditBox::selectText() #206
Conversation
* You could cause a crash/exception by issuing a start value that was greater than the text size. start is now capped at the text length. * Issuing just the start parameter would cause an overflow when added to length, meaning the default length value (npos) would not always represent "end of the text." Now, if length is npos, it will always mean "end of the text."
Thanks again for the extensive testing and for fixing the issue with selectText. I'll merge this PR now and will have a look at the TextArea PR later, but on first glance that one looks great as well. While writing tests for selectText, I discovered that getSelectedText() also has a bug where it doesn't return the correct string if the selection doesn't start at the beginning. I also wrote tests for the getSignal() function in case there were other widgets that didn't override the function, and this also resulted in two typos being found and fixed. While I'm pretty happy with more than 80% of my code being covered by tests, it is starting to look like the remaining part just contains one bug after the other. |
After completing extensive testing I've concluded that the new
onCaretPositionChange
signal added toEditBox
can be merged, barring any additional comments. Here are most of the tests I carried out, which also help describe how the signal operates:I've also identified two cases where giving out-of-bounds values to
EditBox::selectText()
would cause crashes and/or unexpected behaviour:start
to be greater than the length of the text, an out-of-bounds string exception would be thrown. Cappingstart
to the size of the text prevents this from occurring, and it will mean that no text is selected.start
to a non-0 value, but leftlength
to its defaultnpos
value, it would cause an overflow in thestart + length
calculation which would mean thatselectText(1)
would select the first character of the text, and would not start at the second character and select the rest of the text (sincenpos + 1
would overflow to0
). As far as I can tell this does not seem like the intended behaviour, so I've added some code that always explicitly sets the end of the selection to the end of the text whennpos
is given tolength
. You could still cause overflows now but you'd have to go out of your way to do it.