Skip to content

Commit 7b0ee7c

Browse files
committed
Make Action renaming more closely follow the same behaviour as ActionMap
1 parent 249949b commit 7b0ee7c

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsTreeViewItem.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,38 @@ public void UnregisterInputField()
5858
renameTextfield.UnregisterCallback<FocusOutEvent>(e => OnEditTextFinished());
5959
}
6060

61-
private float lastSingleClick;
61+
private double lastSingleClick;
6262
private static InputActionsTreeViewItem selected;
6363

6464
private void OnMouseDownEventForRename(MouseDownEvent e)
6565
{
6666
if (e.clickCount != 1 || e.button != (int)MouseButton.LeftMouse || e.target == null)
6767
return;
68-
69-
if (selected == this && Time.time - lastSingleClick < 3f)
68+
var now = EditorApplication.timeSinceStartup;
69+
if (selected == this && now - lastSingleClick < 3)
7070
{
7171
FocusOnRenameTextField();
7272
e.StopImmediatePropagation();
7373
lastSingleClick = 0;
74+
return;
7475
}
75-
lastSingleClick = Time.time;
76+
lastSingleClick = now;
7677
selected = this;
7778
}
7879

7980
public void Reset()
8081
{
82+
if (m_IsEditing)
83+
{
84+
lastSingleClick = 0;
85+
delegatesFocus = false;
86+
87+
renameTextfield.AddToClassList(InputActionsEditorConstants.HiddenStyleClassName);
88+
label.RemoveFromClassList(InputActionsEditorConstants.HiddenStyleClassName);
89+
s_EditingItem = null;
90+
m_IsEditing = false;
91+
}
8192
EditTextFinished = null;
82-
m_IsEditing = false;
8393
}
8494

8595
public void FocusOnRenameTextField()
@@ -94,7 +104,7 @@ public void FocusOnRenameTextField()
94104

95105
//a bit hacky - e.StopImmediatePropagation() for events does not work like expected on ListViewItems or TreeViewItems because
96106
//the listView/treeView reclaims the focus - this is a workaround with less overhead than rewriting the events
97-
DelayCall();
107+
schedule.Execute(() => renameTextfield.Q<TextField>().Focus()).StartingIn(120);
98108
renameTextfield.SelectAll();
99109

100110
s_EditingItem = this;
@@ -106,12 +116,6 @@ public static void CancelRename()
106116
s_EditingItem?.OnEditTextFinished();
107117
}
108118

109-
async void DelayCall()
110-
{
111-
await Task.Delay(120);
112-
renameTextfield.Q<TextField>().Focus();
113-
}
114-
115119
private void OnEditTextFinished()
116120
{
117121
if (!m_IsEditing)
@@ -130,6 +134,7 @@ private void OnEditTextFinished()
130134
renameTextfield.schedule.Execute(() => renameTextfield.SetValueWithoutNotify(text));
131135
return;
132136
}
137+
133138
EditTextFinished?.Invoke(text);
134139
}
135140
}

0 commit comments

Comments
 (0)