Skip to content

Commit 2934a64

Browse files
authored
FIX: Action Maps contextual menu in Action Editor UI that could display unrelated items. (#2008)
* Fixed Action Maps contextual menu in Action Editor UI that could display unrelated items. * reworked to reduce allocation
1 parent ddc99ca commit 2934a64

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ however, it has to be formatted properly to pass verification tests.
1313
### Fixed
1414
- Fixed Multiple interactions could breaks on Composite Binding. [ISXB-619](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-619)
1515
- Fixed memory leak when the OnScreenStick component was destroyed [ISXB-1070](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1070). Contribution by [LukeUnityDev](https://github.com/LukeUnityDev).
16+
- Fixed Action Maps contextual menu in Action Editor UI that occasionally displays unrelated items.
1617

1718
### Changed
1819
- Renamed editor Resources directories to PackageResources to fix package validation warnings.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal static class ContextMenu
2727
#region ActionMaps
2828
public static void GetContextMenuForActionMapItem(ActionMapsView mapView, InputActionMapsTreeViewItem treeViewItem, int index)
2929
{
30-
_ = new ContextualMenuManipulator(menuEvent =>
30+
treeViewItem.OnContextualMenuPopulateEvent = (menuEvent =>
3131
{
3232
// TODO: AddAction should enable m_RenameOnActionAdded
3333
menuEvent.menu.AppendAction(add_Action_String, _ => mapView.Dispatch(Commands.AddAction()));
@@ -42,7 +42,7 @@ public static void GetContextMenuForActionMapItem(ActionMapsView mapView, InputA
4242
var copiedAction = CopyPasteHelper.GetCopiedClipboardType() == typeof(InputAction);
4343
if (CopyPasteHelper.HasPastableClipboardData(typeof(InputActionMap)))
4444
menuEvent.menu.AppendAction(paste_String, _ => mapView.PasteItems(copiedAction));
45-
}) { target = treeViewItem };
45+
});
4646
}
4747

4848
// Add "Add Action Map" option to empty space under the ListView. Matches with old IMGUI style (ISX-1519).

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// UITK TreeView is not supported in earlier versions
22
// Therefore the UITK version of the InputActionAsset Editor is not available on earlier Editor versions either.
33
#if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
4+
using System;
45
using System.Threading.Tasks;
56
using UnityEditor;
67
using UnityEngine.InputSystem.Editor;
@@ -17,6 +18,7 @@ internal class InputActionMapsTreeViewItem : VisualElement
1718

1819
private const string kRenameTextField = "rename-text-field";
1920
public event EventCallback<string> EditTextFinished;
21+
public Action<ContextualMenuPopulateEvent> OnContextualMenuPopulateEvent;
2022

2123
// for testing purposes to know if the item is focused to accept input
2224
internal bool IsFocused { get; private set; } = false;
@@ -41,6 +43,11 @@ public InputActionMapsTreeViewItem()
4143
RegisterCallback<MouseDownEvent>(OnMouseDownEventForRename);
4244
renameTextfield.RegisterCallback<FocusInEvent>(e => IsFocused = true);
4345
renameTextfield.RegisterCallback<FocusOutEvent>(e => { OnEditTextFinished(); IsFocused = false; });
46+
_ = new ContextualMenuManipulator(menuBuilder =>
47+
{
48+
OnContextualMenuPopulateEvent?.Invoke(menuBuilder);
49+
})
50+
{ target = this };
4451
}
4552

4653
public Label label => this.Q<Label>();

0 commit comments

Comments
 (0)