EditBox: Only emit onReturnOrUnfocus once in cases where Return is pressed and the widget loses focus because of it #227
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.
With the following code:
If you click off the
EditBox
onto thePanel
it's within, you will see"Calling"
output once. However, if you pressReturn
, you will see"Calling"
output twice: once for theReturn
key press, and another for when theEditBox
loses focus due to theTab
selection.Incidentally, if you run the above code without the patch merged to
master
recently, a stack overflow will occur since theEditBox
will never lose focus due to theWidget::setFocus()
call being invoked last and not first.Although the signal being invoked twice is technically correct, I feel like it goes against the spirit of the signal. If you use this signal, you'd typically only want to react to one of the
Return
key press and the unfocus at a time. So this PR adds a small piece of code that prevents emitting the signal more than once at a time.I understand if this change is rejected, although I would argue if you wanted to react to both of them at the same time you'd just connect to the
onUnfocus
andonReturnKeyPress
signals explicitly.