From 4d21dbf9e512355f6b5950e7d1186783197853e9 Mon Sep 17 00:00:00 2001 From: Graham Huws Date: Thu, 15 Feb 2024 00:36:17 +0000 Subject: [PATCH 01/12] FIX: Allow Copy/Paste between windows by intercepting the commands higher up the hierarchy. (ISX-1823) --- Packages/com.unity.inputsystem/CHANGELOG.md | 1 + .../UITKAssetEditor/Views/CopyPasteHelper.cs | 9 +++- .../Views/InputActionsEditorView.cs | 53 +++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index bc6b9c45d5..26424e5d62 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -44,6 +44,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed InputManager.asset file growing in size on each Reset call. - Fixed Opening InputDebugger throws 'Action map must have state at this point' error - Fixed Cut/Paste behaviour to match Editor - Cut items will now be cleared from clipboard after pasting. +- Fixed Pasting items between windows not working until an item in the Action Map/Action lists was selected. ## [1.8.0-pre.2] - 2023-11-09 diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs index badbbd8e70..a5f54566f9 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs @@ -204,6 +204,10 @@ private static void PasteActionsFromClipboard(InputActionsEditorState state, boo var index = state.selectedActionIndex; if (addLast) index = actionArray.arraySize - 1; + + if (index < 0) + index = 0; + PasteData(EditorGUIUtility.systemCopyBuffer, new[] {index}, actionArray); } @@ -288,13 +292,14 @@ private static void PasteAction(SerializedProperty arrayProperty, string jsonToI private static int PasteBindingOrComposite(SerializedProperty arrayProperty, string json, int index, string actionName, bool createCompositeParts = true) { var pastePartOfComposite = IsPartOfComposite(json); - if (index > 0) + if (index > 0 && arrayProperty.arraySize > 0 && index - 1 < arrayProperty.arraySize) { var currentProperty = arrayProperty.GetArrayElementAtIndex(index - 1); var currentIsComposite = IsComposite(currentProperty) || IsPartOfComposite(currentProperty); if (pastePartOfComposite && !currentIsComposite) //prevent pasting part of composite into non-composite return index; } + index = pastePartOfComposite || s_State.selectionType == SelectionType.Action ? index : Selectors.GetSelectedBindingIndexAfterCompositeBindings(s_State) + 1; if (json.Contains(k_BindingData)) //copied data is composite with bindings - only true for directly copied composites, not for composites from copied actions return PasteCompositeFromJson(arrayProperty, json, index, actionName); @@ -351,7 +356,7 @@ private static bool IsPartOfComposite(string json) private static SerializedProperty AddElement(SerializedProperty arrayProperty, string name, int index = -1) { var uniqueName = InputActionSerializationHelpers.FindUniqueName(arrayProperty, name); - if (index < 0) + if (index < 0 || index > arrayProperty.arraySize) index = arrayProperty.arraySize; arrayProperty.InsertArrayElementAtIndex(index); diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs index c8d91fa9e6..bd41c775af 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs @@ -1,4 +1,5 @@ #if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS +using CmdEvents = UnityEngine.InputSystem.Editor.InputActionsEditorConstants.CommandEvents; using System; using System.Collections.Generic; using System.Linq; @@ -14,6 +15,8 @@ internal class InputActionsEditorView : ViewBase("actions-tree-view"); + m_ActionMapsListView = root.Q("action-maps-list-view"); + + root.RegisterCallback(OnValidateCommand); + root.RegisterCallback(OnExecuteCommand); + root.focusable = true; // Required for CommandEvents to work } private void OnReset() @@ -159,6 +169,49 @@ public class ViewState public IEnumerable controlSchemes; public int selectedControlSchemeIndex; } + + void OnExecuteCommand(ExecuteCommandEvent evt) + { + if (evt.commandName != CmdEvents.Paste) + return; + + var copiedType = CopyPasteHelper.GetCopiedClipboardType(); + + if (copiedType == typeof(InputActionMap)) + { + Dispatch(Commands.PasteActionMaps()); + } + else if (copiedType == typeof(InputAction)) + { + // Can't paste an Action without any Action Maps for it to go to + if (m_ActionMapsListView.itemsSource.Count > 0) + Dispatch(Commands.PasteActionsOrBindings()); + } + else if (copiedType == typeof(InputBinding)) + { + // Can't paste a Binding without any Actions for it to go to + if (m_ActionsTreeView.itemsSource.Count > 0) + { + var oldSelectedBinding = stateContainer.GetState().selectedBindingIndex; + Dispatch(Commands.PasteActionsOrBindings()); + + // If paste succeeded, expand the relevant Action to show the new binding. + if (stateContainer.GetState().selectedBindingIndex != oldSelectedBinding) + m_ActionsTreeView.ExpandItem(m_ActionsTreeView.GetIdForIndex(stateContainer.GetState().selectedActionIndex)); + } + } + } + + void OnValidateCommand(ValidateCommandEvent evt) + { + // Mark commands as supported for Execute by stopping propagation of the event + switch (evt.commandName) + { + case CmdEvents.Paste: + evt.StopPropagation(); + break; + } + } } internal static partial class Selectors From 9cda4d84bdcc26f316bcf25c9b1ec86a6110de60 Mon Sep 17 00:00:00 2001 From: Graham Huws Date: Tue, 20 Feb 2024 11:18:59 +0000 Subject: [PATCH 02/12] Address feedback, and fix focusing when tabbing in to the window for events to work. --- Packages/com.unity.inputsystem/CHANGELOG.md | 2 +- .../Editor/UITKAssetEditor/InputActionsEditorWindow.cs | 6 ++++++ .../Editor/UITKAssetEditor/Views/CopyPasteHelper.cs | 9 +++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 41b0c766ab..69ae38cb51 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -46,7 +46,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed Cut/Paste behaviour to match Editor - Cut items will now be cleared from clipboard after pasting. - Fixed InputAction asset appearing dirty after rename [ISXB-695](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-749) - Fixed Error logged when InputActionEditor window opened without a valid asset -- Fixed Pasting items between windows not working until an item in the Action Map/Action lists was selected. +- Fixed Pasting items between Input Action Editor windows having no effect until an item in the Action Map/Action lists was selected. ## [1.8.0-pre.2] - 2023-11-09 diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index f50150f20c..fcc6753500 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -249,6 +249,12 @@ private bool HasAssetChanged(SerializedObject serializedAsset) return newAssetJson != m_AssetJson; } + private void OnFocus() + { + // Apply focus here so that Paste works when users tab into the window (handled in InputActionsEditorView) + rootVisualElement.Focus(); + } + private void OnLostFocus() { // Auto-save triggers on focus-lost instead of on every change diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs index a5f54566f9..45e00723e0 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs @@ -205,8 +205,7 @@ private static void PasteActionsFromClipboard(InputActionsEditorState state, boo if (addLast) index = actionArray.arraySize - 1; - if (index < 0) - index = 0; + index = Math.Clamp(index, 0, actionArray.arraySize - 1); PasteData(EditorGUIUtility.systemCopyBuffer, new[] {index}, actionArray); } @@ -292,9 +291,11 @@ private static void PasteAction(SerializedProperty arrayProperty, string jsonToI private static int PasteBindingOrComposite(SerializedProperty arrayProperty, string json, int index, string actionName, bool createCompositeParts = true) { var pastePartOfComposite = IsPartOfComposite(json); - if (index > 0 && arrayProperty.arraySize > 0 && index - 1 < arrayProperty.arraySize) + var currentPropertyIndex = index - 1; + // We don't care about these checks if the array index is invalid + if (currentPropertyIndex >= 0 && currentPropertyIndex < arrayProperty.arraySize) { - var currentProperty = arrayProperty.GetArrayElementAtIndex(index - 1); + var currentProperty = arrayProperty.GetArrayElementAtIndex(currentPropertyIndex); var currentIsComposite = IsComposite(currentProperty) || IsPartOfComposite(currentProperty); if (pastePartOfComposite && !currentIsComposite) //prevent pasting part of composite into non-composite return index; From 108c2689020f950fcc842b1c0bea8d7b7928f025 Mon Sep 17 00:00:00 2001 From: Graham Huws Date: Tue, 20 Feb 2024 15:18:06 +0000 Subject: [PATCH 03/12] Catch errors, and simplify OnExecuteCommand. --- .../UITKAssetEditor/Views/ActionMapsView.cs | 3 ++- .../UITKAssetEditor/Views/CopyPasteHelper.cs | 5 +++++ .../Views/InputActionsEditorView.cs | 18 ++++++------------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs index c40971dcd4..3ef00da591 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs @@ -201,7 +201,8 @@ private void OnPointerDown(PointerDownEvent evt) if (evt.button == (int)MouseButton.RightMouse && evt.clickCount == 1) { var actionMap = (evt.target as VisualElement).GetFirstAncestorOfType(); - m_ListView.SetSelection(actionMap.parent.IndexOf(actionMap)); + if (actionMap != null) + m_ListView.SetSelection(actionMap.parent.IndexOf(actionMap)); } } diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs index 45e00723e0..c58ced0c76 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs @@ -215,6 +215,11 @@ private static void PasteBindingsFromClipboard(InputActionsEditorState state) var actionMap = Selectors.GetSelectedActionMap(state)?.wrappedProperty; var bindingsArray = actionMap?.FindPropertyRelative(nameof(InputActionMap.m_Bindings)); var actions = actionMap?.FindPropertyRelative(nameof(InputActionMap.m_Actions)); + + // Don't do anything if there's no valid array to paste into. + if (state.selectedActionIndex == -1 || actions == null || bindingsArray == null) + return; + var index = state.selectionType == SelectionType.Action ? Selectors.GetBindingIndexBeforeAction(actions, state.selectedActionIndex, bindingsArray) : state.selectedBindingIndex; PasteData(EditorGUIUtility.systemCopyBuffer, new[] {index}, bindingsArray); } diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs index bd41c775af..2b44e149ec 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs @@ -183,22 +183,16 @@ void OnExecuteCommand(ExecuteCommandEvent evt) } else if (copiedType == typeof(InputAction)) { - // Can't paste an Action without any Action Maps for it to go to - if (m_ActionMapsListView.itemsSource.Count > 0) - Dispatch(Commands.PasteActionsOrBindings()); + Dispatch(Commands.PasteActionsOrBindings()); } else if (copiedType == typeof(InputBinding)) { - // Can't paste a Binding without any Actions for it to go to - if (m_ActionsTreeView.itemsSource.Count > 0) - { - var oldSelectedBinding = stateContainer.GetState().selectedBindingIndex; - Dispatch(Commands.PasteActionsOrBindings()); + var oldSelectedBinding = stateContainer.GetState().selectedBindingIndex; + Dispatch(Commands.PasteActionsOrBindings()); - // If paste succeeded, expand the relevant Action to show the new binding. - if (stateContainer.GetState().selectedBindingIndex != oldSelectedBinding) - m_ActionsTreeView.ExpandItem(m_ActionsTreeView.GetIdForIndex(stateContainer.GetState().selectedActionIndex)); - } + // If paste succeeded, expand the relevant Action to show the new binding. + if (stateContainer.GetState().selectedBindingIndex != oldSelectedBinding) + m_ActionsTreeView.ExpandItem(m_ActionsTreeView.GetIdForIndex(stateContainer.GetState().selectedActionIndex)); } } From 384cb7419cf4cb13745c13fbdddafdf8a5acd532 Mon Sep 17 00:00:00 2001 From: Graham Huws Date: Tue, 20 Feb 2024 21:48:14 +0000 Subject: [PATCH 04/12] Avoid array OOB. --- .../InputSystem/Editor/UITKAssetEditor/Views/Selectors.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/Selectors.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/Selectors.cs index aa521f19f1..534b950175 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/Selectors.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/Selectors.cs @@ -79,7 +79,7 @@ public static int GetSelectedBindingIndexAfterCompositeBindings(InputActionsEdit var item = new SerializedInputBinding(bindings?.GetArrayElementAtIndex(state.selectedBindingIndex)); var index = state.selectedBindingIndex + (item.isComposite || item.isPartOfComposite ? 1 : 0); var toSkip = 0; - while (new SerializedInputBinding(bindings?.GetArrayElementAtIndex(index)).isPartOfComposite) + while (index < bindings.arraySize && new SerializedInputBinding(bindings?.GetArrayElementAtIndex(index)).isPartOfComposite) { toSkip++; index++; From b7617fe45c29608b546d237d285a326d9e1efdad Mon Sep 17 00:00:00 2001 From: Graham Huws Date: Wed, 21 Feb 2024 15:58:11 +0000 Subject: [PATCH 05/12] Deduplicate Paste handling. --- .../Editor/UITKAssetEditor/Views/ActionMapsView.cs | 8 ++------ .../Editor/UITKAssetEditor/Views/ActionsTreeView.cs | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs index 97723acec9..e5bbaec20a 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs @@ -155,6 +155,7 @@ private void OnExecuteCommand(ExecuteCommandEvent evt) if (allowUICommandExecution) { + // NB: Paste is handled in InputActionsEditorView. switch (evt.commandName) { case CmdEvents.Rename: @@ -173,11 +174,6 @@ private void OnExecuteCommand(ExecuteCommandEvent evt) case CmdEvents.Cut: CutItems(); break; - case CmdEvents.Paste: - var isActionCopied = CopyPasteHelper.GetCopiedClipboardType() == typeof(InputAction); - if (CopyPasteHelper.HasPastableClipboardData(typeof(InputActionMap))) - PasteItems(isActionCopied); - break; default: return; // Skip StopPropagation if we didn't execute anything } @@ -191,6 +187,7 @@ private void OnExecuteCommand(ExecuteCommandEvent evt) private void OnValidateCommand(ValidateCommandEvent evt) { // Mark commands as supported for Execute by stopping propagation of the event + // Paste is handled in InputActionsEditorView. switch (evt.commandName) { case CmdEvents.Rename: @@ -199,7 +196,6 @@ private void OnValidateCommand(ValidateCommandEvent evt) case CmdEvents.Duplicate: case CmdEvents.Copy: case CmdEvents.Cut: - case CmdEvents.Paste: evt.StopPropagation(); break; } diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs index eb3f66fa25..8bacbb77e2 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs @@ -387,6 +387,7 @@ private void OnExecuteCommand(ExecuteCommandEvent evt) if (allowUICommandExecution) { + // NB: Paste is handled in InputActionsEditorView. var data = (ActionOrBindingData)m_ActionsTreeView.selectedItem; switch (evt.commandName) { @@ -409,11 +410,6 @@ private void OnExecuteCommand(ExecuteCommandEvent evt) case CmdEvents.Cut: CutItems(); break; - case CmdEvents.Paste: - var hasPastableData = CopyPasteHelper.HasPastableClipboardData(data.isAction ? typeof(InputAction) : typeof(InputBinding)); - if (hasPastableData) - PasteItems(); - break; default: return; // Skip StopPropagation if we didn't execute anything } @@ -427,6 +423,7 @@ private void OnExecuteCommand(ExecuteCommandEvent evt) private void OnValidateCommand(ValidateCommandEvent evt) { // Mark commands as supported for Execute by stopping propagation of the event + // Paste is handled in InputActionsEditorView. switch (evt.commandName) { case CmdEvents.Rename: @@ -435,7 +432,6 @@ private void OnValidateCommand(ValidateCommandEvent evt) case CmdEvents.Duplicate: case CmdEvents.Copy: case CmdEvents.Cut: - case CmdEvents.Paste: evt.StopPropagation(); break; } From 2e64bb2f37d70bfc21ab487419be48bd82e71d80 Mon Sep 17 00:00:00 2001 From: Graham Huws Date: Wed, 21 Feb 2024 16:10:03 +0000 Subject: [PATCH 06/12] Fix SelectBinding not doing so, and simplify Paste handling. --- .../UITKAssetEditor/InputActionsEditorState.cs | 2 +- .../Views/InputActionsEditorView.cs | 16 +--------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorState.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorState.cs index 2f4137f398..5511ad8eef 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorState.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorState.cs @@ -178,7 +178,7 @@ public InputActionsEditorState SelectBinding(int index) //if no binding selected (due to no bindings in list) set selection type to action if (index == -1) return With(selectedBindingIndex: index, selectionType: SelectionType.Action); - return With(selectedBindingIndex: index); + return With(selectedBindingIndex: index, selectionType: SelectionType.Binding); } public InputActionsEditorState SelectAction(int index) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs index 6fb2cb0ad2..2e6e08a8b5 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs @@ -15,8 +15,6 @@ internal class InputActionsEditorView : ViewBase("actions-tree-view"); - m_ActionMapsListView = root.Q("action-maps-list-view"); - root.RegisterCallback(OnValidateCommand); root.RegisterCallback(OnExecuteCommand); root.focusable = true; // Required for CommandEvents to work @@ -243,19 +238,10 @@ void OnExecuteCommand(ExecuteCommandEvent evt) { Dispatch(Commands.PasteActionMaps()); } - else if (copiedType == typeof(InputAction)) + else if (copiedType == typeof(InputAction) || copiedType == typeof(InputBinding)) { Dispatch(Commands.PasteActionsOrBindings()); } - else if (copiedType == typeof(InputBinding)) - { - var oldSelectedBinding = stateContainer.GetState().selectedBindingIndex; - Dispatch(Commands.PasteActionsOrBindings()); - - // If paste succeeded, expand the relevant Action to show the new binding. - if (stateContainer.GetState().selectedBindingIndex != oldSelectedBinding) - m_ActionsTreeView.ExpandItem(m_ActionsTreeView.GetIdForIndex(stateContainer.GetState().selectedActionIndex)); - } } void OnValidateCommand(ValidateCommandEvent evt) From 7ae236a9f3854eb23e184f43276d064ed94cd7b2 Mon Sep 17 00:00:00 2001 From: Graham Huws Date: Thu, 22 Feb 2024 12:01:22 +0000 Subject: [PATCH 07/12] Fix array index bounds. Clamp doesn't work if arraySize is 0. --- .../Editor/UITKAssetEditor/Views/CopyPasteHelper.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs index a119a3bc79..3b2199cd1f 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs @@ -211,11 +211,12 @@ private static void PasteActionsFromClipboard(InputActionsEditorState state, boo : Selectors.GetSelectedActionMap(state)?.wrappedProperty; var actionArray = actionMap?.FindPropertyRelative(nameof(InputActionMap.m_Actions)); if (actionArray == null) return; + var index = state.selectedActionIndex; - if (addLast) + if (addLast || index >= actionArray.arraySize) index = actionArray.arraySize - 1; - - index = Math.Clamp(index, 0, actionArray.arraySize - 1); + if (index < 0) + index = 0; PasteData(EditorGUIUtility.systemCopyBuffer, new[] {index}, actionArray); } From a5e7de0d2249a6a687805cd404979a36fdd27782 Mon Sep 17 00:00:00 2001 From: Graham Huws Date: Thu, 22 Feb 2024 12:07:16 +0000 Subject: [PATCH 08/12] Catch issue with pasting a binding into an empty map. --- .../InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs index 3b2199cd1f..445504ade0 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs @@ -228,7 +228,7 @@ private static void PasteBindingsFromClipboard(InputActionsEditorState state) var actions = actionMap?.FindPropertyRelative(nameof(InputActionMap.m_Actions)); // Don't do anything if there's no valid array to paste into. - if (state.selectedActionIndex == -1 || actions == null || bindingsArray == null) + if (state.selectedActionIndex == -1 || actions == null || actions.arraySize == 0 || bindingsArray == null) return; var index = state.selectionType == SelectionType.Action ? Selectors.GetBindingIndexBeforeAction(actions, state.selectedActionIndex, bindingsArray) : state.selectedBindingIndex; From 1b56964f761c5deaf51be6128a1a9230ce4bc800 Mon Sep 17 00:00:00 2001 From: Graham Huws Date: Thu, 22 Feb 2024 12:39:21 +0000 Subject: [PATCH 09/12] Fix formatting after merge --- .../InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs index b539ec67e6..f8edc5af12 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs @@ -211,7 +211,7 @@ private static void PasteActionsFromClipboard(InputActionsEditorState state, boo : Selectors.GetSelectedActionMap(state)?.wrappedProperty; var actionArray = actionMap?.FindPropertyRelative(nameof(InputActionMap.m_Actions)); if (actionArray == null) return; - + var index = state.selectedActionIndex; if (addLast || index >= actionArray.arraySize) index = actionArray.arraySize - 1; From 5c4aa27067c6587112784edcf56c049dead50edf Mon Sep 17 00:00:00 2001 From: Graham Huws Date: Tue, 27 Feb 2024 11:21:38 +0000 Subject: [PATCH 10/12] Stop propagation of paste event when we handle it. --- .../Editor/UITKAssetEditor/Views/InputActionsEditorView.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs index 2e6e08a8b5..2fa461c8f5 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs @@ -236,10 +236,12 @@ void OnExecuteCommand(ExecuteCommandEvent evt) if (copiedType == typeof(InputActionMap)) { + evt.StopPropagation(); Dispatch(Commands.PasteActionMaps()); } else if (copiedType == typeof(InputAction) || copiedType == typeof(InputBinding)) { + evt.StopPropagation(); Dispatch(Commands.PasteActionsOrBindings()); } } From 519abd9a0db99442de79ca35c9a3ff2792392d6b Mon Sep 17 00:00:00 2001 From: Graham Huws Date: Mon, 4 Mar 2024 12:38:30 +0000 Subject: [PATCH 11/12] Update after merging develop --- .../Views/InputActionsEditorView.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs index 7f91aa785f..6538bc7b71 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs @@ -23,6 +23,9 @@ internal class InputActionsEditorView : ViewBase("control-schemes-toolbar-menu"); m_ControlSchemesToolbar.menu.AppendAction("Add Control Scheme...", _ => AddOrUpdateControlScheme(root)); @@ -256,12 +260,12 @@ void OnExecuteCommand(ExecuteCommandEvent evt) if (copiedType == typeof(InputActionMap)) { evt.StopPropagation(); - Dispatch(Commands.PasteActionMaps()); + m_ActionMapsView.PasteItems(false); } else if (copiedType == typeof(InputAction) || copiedType == typeof(InputBinding)) { evt.StopPropagation(); - Dispatch(Commands.PasteActionsOrBindings()); + m_ActionsTreeView.PasteItems(); } } From 6227e7e5d0283bef32587b33d93251948169e948 Mon Sep 17 00:00:00 2001 From: Graham Huws Date: Tue, 12 Mar 2024 14:23:07 +0000 Subject: [PATCH 12/12] Make use of allowUICommandExecution protection bool like in other Views. --- .../Views/InputActionsEditorView.cs | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs index 2554433d5a..e7cf90cfab 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs @@ -251,20 +251,25 @@ public class ViewState void OnExecuteCommand(ExecuteCommandEvent evt) { - if (evt.commandName != CmdEvents.Paste) - return; + if (allowUICommandExecution) + { + if (evt.commandName != CmdEvents.Paste) + return; - var copiedType = CopyPasteHelper.GetCopiedClipboardType(); + var copiedType = CopyPasteHelper.GetCopiedClipboardType(); - if (copiedType == typeof(InputActionMap)) - { - evt.StopPropagation(); - m_ActionMapsView.PasteItems(false); - } - else if (copiedType == typeof(InputAction) || copiedType == typeof(InputBinding)) - { - evt.StopPropagation(); - m_ActionsTreeView.PasteItems(); + if (copiedType == typeof(InputActionMap)) + { + evt.StopPropagation(); + m_ActionMapsView.PasteItems(false); + allowUICommandExecution = false; + } + else if (copiedType == typeof(InputAction) || copiedType == typeof(InputBinding)) + { + evt.StopPropagation(); + m_ActionsTreeView.PasteItems(); + allowUICommandExecution = false; + } } }