Search Issue Tracker
Won't Fix
Votes
0
Found in
6000.0.47f1
6000.1.0b15
6000.2.0a9
Issue ID
UUM-103308
Regression
Yes
TextField.RegisterCallback<KeyDownEvent>() doesn't collect keystrokes when entering text into the TextField
Reproduction steps:
1. Open the attached project "ReproProj"
2. Open “Echo Console“ (Window > General > Echo Console)
3. In the TextField, enter “Hello“
4. Press the “Enter” key twice
5. Enter “Hey“
6. Press the “up” arrow key
Expected result: Arrow keys access input history, and the “Hello” appears in the TextField
Actual result: Caret moves to the front of the entered text
Reproducible with: 2023.2.0a6 (5de4d4fd9e52), 6000.0.47f1, 6000.1.0b15, 6000.2.0a9
Not reproducible with: 2022.3.61f1, 2023.2.0a5 (e4a766a8b34d)
Testing environment: Windows 10 Enterprise 21H2
Not reproducible on: No other environment tested
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Out-of-bounds memory access with multiple CanvasRenderers under a Canvas when using Mesh API
- Inspector tries to access file after it was deleted when the file was locked in Inspector window
- Changing Transform values in Search window Inspector loses focus while dragging and stopping mouse without releasing dragging action
- Saving changes on the dirty VFX Graph during the Play mode throws "The referenced script (Unknown) on this Behaviour is missing!" warnings
- VFX Graph Debug Info overlaps the "Initialize" block debug info by default
Resolution Note:
To prevent the default handling of the arrow keys by the TextField, you need to register the callback as a "TrickleDown" callback, meaning that you will receive the event before it is processed by the TextField. You can then have your own handling of it and stop the propagation of the event.
In your case, you want to keep the handling of the "Enter" as a "NoTrickleDown" callback (assuming you want to keep the double "Enter" to submit the value).
Here is an updated version of your callbacks that should achieve your desired result:
// *** THE POINT OF MY BUG SUBMISSION IS THIS CALLBACK ***
// Customize hotkeys for the input textfield
input.RegisterCallback<KeyDownEvent>(evt =>
{
// Hitting up and down advances through the input history to use prior submissions
if (evt.keyCode == KeyCode.UpArrow)
{
if (_inputHistory.Count > 0)
{
if (_inputHistoryIndex > 0)
{
_inputHistoryIndex--;
}
input.value = _inputHistory[_inputHistoryIndex];
input.textSelection.cursorIndex = input.textSelection.selectIndex = input.value?.Length ?? 0;
evt.StopImmediatePropagation();
}
}
else if (evt.keyCode == KeyCode.DownArrow)
{
if (_inputHistory.Count > 0)
{
if (_inputHistoryIndex < _inputHistory.Count - 1)
{
_inputHistoryIndex++;
}
input.value = _inputHistory[_inputHistoryIndex];
input.textSelection.cursorIndex = input.textSelection.selectIndex = input.value?.Length ?? 0;
evt.StopImmediatePropagation();
}
}
}, TrickleDown.TrickleDown);
input.RegisterCallback<KeyDownEvent>(evt =>
{
// Hitting enter submits the text of the input textfield
if (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter)
{
onSubmit();
}
});