EditBox: Add onCaretPositionChange Signal and Fix Bugs in EditBox::selectText() #206
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.
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.