Search Issue Tracker
Won't Fix
Won't Fix in 2023.1.X
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
- 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:
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.
Resolution Note (2023.1.X):
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.