-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Bug] ListView Lost focus every time enter value #97
Comments
@AnnulusGames The cause seems to be the PropertyListView class. |
This bug is troubling me too. |
It seems Unity changed something with |
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.UIElements;
using Alchemy.Inspector;
namespace Alchemy.Editor.Elements
{
/// <summary>
/// Visual Element that draws SerializedProperty of Array or List
/// </summary>
public sealed class PropertyListView : BindableElement
{
public PropertyListView(SerializedProperty property)
{
Assert.IsTrue(property.isArray);
var parentObj = property.GetDeclaredObject();
var events = property.GetAttribute<OnListViewChangedAttribute>(true);
VisualElement lastFocusedElement = null;
listView = GUIHelper.CreateListViewFromFieldInfo(parentObj, property.GetFieldInfo());
listView.headerTitle = ObjectNames.NicifyVariableName(property.displayName);
listView.bindItem = (element, index) =>
{
var arrayElement = property.GetArrayElementAtIndex(index);
var e = new AlchemyPropertyField(arrayElement, property.GetPropertyType(true), true);
element.Add(e);
element.Bind(arrayElement.serializedObject);
var field = lastFocusedElement?.Q<TextField>();
if (field != null)
{
field.Focus();
field.SelectRange(field.value.Length, field.value.Length);
using var evt = KeyboardEventBase<KeyDownEvent>.GetPooled('\0', KeyCode.RightArrow, EventModifiers.FunctionKey);
field.SendEvent(evt);
}
if (events != null)
{
e.TrackPropertyValue(arrayElement, x =>
{
ReflectionHelper.Invoke(parentObj, events.OnItemChanged,
new object[] { index, x.GetValue<object>() });
});
}
};
listView.unbindItem = (element, index) =>
{
lastFocusedElement = element;
element.Clear();
element.Unbind();
};
var label = listView.Q<Label>();
if (label != null) label.style.unityFontStyleAndWeight = FontStyle.Bold;
listView.BindProperty(property);
Add(listView);
}
readonly ListView listView;
public string Label
{
get => listView.headerTitle;
set => listView.headerTitle = value;
}
}
} |
Unity 2022.3.51f doesn't have this anymore. Probably fixed in later versions Unity6 too |
Alchemy v2.0.1
Unity 6000.0.f14
bandicam.2024-08-15.10-53-35-835.mp4
Every time I fill in a value, the focus is lost and I have to click again to continue filling in.
The text was updated successfully, but these errors were encountered: