Search Issue Tracker
Won't Fix
Votes
0
Found in
2022.1.23f1
2022.2.0b16
2023.1.0a21
Issue ID
UUM-20731
Regression
No
TextField cursorIndex / selectionIndex are not set in time for Focus/Mouse events
Summary:
I have a TextField txtf with txtf.selectAllOnFocus = txtf.selectAllOnMouseUp = false.
When the user clicks into the text field, I want to know the cursor and selection indices, but I only get the previous indicies, not the ones after the click.
Also refer to this slack discussion.]
Extra Notes:
Try something like this and observe the indices in the test output. Same is true for FocusEvent or MouseUpEvent.
{code:java}
var txtf = new TextField() { value = "Hello World!" };
txtf.selectAllOnFocus = txtf.selectAllOnMouseUp = false;
txtf.RegisterCallback<MouseDownEvent>(UpdateMenu);
void UpdateMenu(EventBase evt)
{
if (evt.target is not TextField txtf) return;
Debug.Log($"MouseDown on TextField: {txtf.cursorIndex}, {txtf.selectIndex}");
} {code}
I have no idea if this is a regression or not!
Expected Results:
I would expect some event that allow me to read to new indices based on the users click position.
Actual Results:
I only get the previous indices, i.e. the first one is always (0, 0), subsequent clicks yield the cursor position from before the click.
Tested on:
Unity Version 2021.1.4f1, Operating System WIN10.
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
- Mono Windows Builds don't produce full log callstacks when generating logs
- AssetBundles fail to load when running in Built Players for Mobile Devices
- UI elements with text gets bigger and grey when Player window is moved to another screen with different resolution
- System name accepts multiline text but crops it on confirmation, duplicates input, and shrinks the field when empty
- UI element scale and position are wrong in project build when DRS is changed with HDR and Software Dynamic Resolution enabled
Resolution Note:
An important refactor to the Event system landed in 2023.2, which fixes the issue.
In previous versions, the trickle-down and bubble-up phases are executed before the ExecuteDefaultActionAtTarget. The workaround for these versions would be to wait for one frame before accessing the selection indices.