Skip to content

Commit 1e71287

Browse files
authored
FIX: Only allow a single Paste after Cutting an item (ISX-1821) (#1838)
* FIX: Only allow a single Paste after Cutting an item (ISX-1821) * Address feedback
1 parent 3314fcf commit 1e71287

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ however, it has to be formatted properly to pass verification tests.
4040
- Fixed console errors that can be produced when opening input package settings from the Inspector.
4141
- Fixed InputManager.asset file growing in size on each Reset call.
4242
- Fixed Opening InputDebugger throws 'Action map must have state at this point' error
43+
- Fixed Cut/Paste behaviour to match Editor - Cut items will now be cleared from clipboard after pasting.
4344

4445
## [1.8.0-pre.2] - 2023-11-09
4546

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/Commands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static Command CutActionMapSelection()
110110
{
111111
return (in InputActionsEditorState state) =>
112112
{
113-
CopyPasteHelper.CopyActionMap(state);
113+
CopyPasteHelper.CutActionMap(state);
114114
return DeleteActionMap(state.selectedActionMapIndex).Invoke(state);
115115
};
116116
}
@@ -128,7 +128,7 @@ public static Command CutActionsOrBindings()
128128
{
129129
return (in InputActionsEditorState state) =>
130130
{
131-
CopyPasteHelper.Copy(state);
131+
CopyPasteHelper.Cut(state);
132132
return state.selectionType == SelectionType.Action ?
133133
DeleteAction(state.selectedActionMapIndex, Selectors.GetSelectedAction(state)?.wrappedProperty.FindPropertyRelative(nameof(InputAction.m_Name)).stringValue).Invoke(state)
134134
: DeleteBinding(state.selectedActionMapIndex, state.selectedBindingIndex).Invoke(state);

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,28 @@ internal static class CopyPasteHelper
2222

2323
private static SerializedProperty s_lastAddedElement;
2424
private static InputActionsEditorState s_State;
25+
private static bool s_lastClipboardActionWasCut = false;
2526

2627
private static bool IsComposite(SerializedProperty property) => property.FindPropertyRelative("m_Flags").intValue == (int)InputBinding.Flags.Composite;
2728
private static bool IsPartOfComposite(SerializedProperty property) => property.FindPropertyRelative("m_Flags").intValue == (int)InputBinding.Flags.PartOfComposite;
2829
private static string PropertyName(SerializedProperty property) => property.FindPropertyRelative("m_Name").stringValue;
2930

31+
#region Cut
32+
33+
public static void CutActionMap(InputActionsEditorState state)
34+
{
35+
CopyActionMap(state);
36+
s_lastClipboardActionWasCut = true;
37+
}
38+
39+
public static void Cut(InputActionsEditorState state)
40+
{
41+
Copy(state);
42+
s_lastClipboardActionWasCut = true;
43+
}
44+
45+
#endregion
46+
3047
#region Copy
3148

3249
public static void CopyActionMap(InputActionsEditorState state)
@@ -54,6 +71,7 @@ private static void CopySelectedTreeViewItemsToClipboard(List<SerializedProperty
5471
var copyBuffer = new StringBuilder();
5572
CopyItems(items, copyBuffer, type, actionMap);
5673
EditorGUIUtility.systemCopyBuffer = copyBuffer.ToString();
74+
s_lastClipboardActionWasCut = false;
5775
}
5876

5977
private static void CopyItems(List<SerializedProperty> items, StringBuilder buffer, Type type, SerializedProperty actionMap)
@@ -152,6 +170,11 @@ public static SerializedProperty PasteActionMapsFromClipboard(InputActionsEditor
152170
s_State = state;
153171
var actionMapArray = state.serializedObject.FindProperty(nameof(InputActionAsset.m_ActionMaps));
154172
PasteData(EditorGUIUtility.systemCopyBuffer, new[] {state.selectedActionMapIndex}, actionMapArray);
173+
174+
// Don't want to be able to paste repeatedly after a cut - ISX-1821
175+
if (s_lastAddedElement != null && s_lastClipboardActionWasCut)
176+
EditorGUIUtility.systemCopyBuffer = string.Empty;
177+
155178
return s_lastAddedElement;
156179
}
157180

@@ -164,6 +187,11 @@ public static SerializedProperty PasteActionsOrBindingsFromClipboard(InputAction
164187
PasteActionsFromClipboard(state, addLast);
165188
if (typeOfCopiedData == typeof(InputBinding))
166189
PasteBindingsFromClipboard(state);
190+
191+
// Don't want to be able to paste repeatedly after a cut - ISX-1821
192+
if (s_lastAddedElement != null && s_lastClipboardActionWasCut)
193+
EditorGUIUtility.systemCopyBuffer = string.Empty;
194+
167195
return s_lastAddedElement;
168196
}
169197

0 commit comments

Comments
 (0)