Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Allow Copy/Paste between windows (ISX-1823). #1844

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4d21dbf
FIX: Allow Copy/Paste between windows by intercepting the commands hi…
graham-huws Feb 15, 2024
4e41f29
Merge branch 'develop' into ISX-1823-cut-copy-between-windows
lyndon-unity Feb 18, 2024
9cda4d8
Address feedback, and fix focusing when tabbing in to the window for …
graham-huws Feb 20, 2024
108c268
Catch errors, and simplify OnExecuteCommand.
graham-huws Feb 20, 2024
5b5e663
Merge branch 'develop' into ISX-1823-cut-copy-between-windows
graham-huws Feb 20, 2024
384cb74
Avoid array OOB.
graham-huws Feb 20, 2024
b7617fe
Deduplicate Paste handling.
graham-huws Feb 21, 2024
2e64bb2
Fix SelectBinding not doing so, and simplify Paste handling.
graham-huws Feb 21, 2024
7ae236a
Fix array index bounds. Clamp doesn't work if arraySize is 0.
graham-huws Feb 22, 2024
a5e7de0
Catch issue with pasting a binding into an empty map.
graham-huws Feb 22, 2024
9a9cf85
Merge branch 'develop' into ISX-1823-cut-copy-between-windows
graham-huws Feb 22, 2024
78904a7
Merge branch 'develop' into ISX-1823-cut-copy-between-windows
Pauliusd01 Feb 22, 2024
1b56964
Fix formatting after merge
graham-huws Feb 22, 2024
3179bf0
Merge branch 'develop' into ISX-1823-cut-copy-between-windows
graham-huws Feb 23, 2024
0774a65
Merge remote-tracking branch 'origin/develop' into ISX-1823-cut-copy-…
ritamerkl Feb 26, 2024
5c4aa27
Stop propagation of paste event when we handle it.
graham-huws Feb 27, 2024
2bad8bb
Merge branch 'develop' into ISX-1823-cut-copy-between-windows
graham-huws Feb 29, 2024
d1d99a9
Merge branch 'develop' into ISX-1823-cut-copy-between-windows
graham-huws Mar 4, 2024
519abd9
Update after merging develop
graham-huws Mar 4, 2024
80b2705
Merge branch 'develop' into ISX-1823-cut-copy-between-windows
graham-huws Mar 12, 2024
6227e7e
Make use of allowUICommandExecution protection bool like in other Views.
graham-huws Mar 12, 2024
0abdaef
Merge branch 'develop' into ISX-1823-cut-copy-between-windows
graham-huws Apr 4, 2024
81f78f9
Merge branch 'develop' into ISX-1823-cut-copy-between-windows
graham-huws May 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
graham-huws marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
graham-huws marked this conversation as resolved.
Show resolved Hide resolved

PasteData(EditorGUIUtility.systemCopyBuffer, new[] {index}, actionArray);
}

Expand Down Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused about an index that must be greater than zero and at least two elements from the end of the anway? Would recommend adding an inline comment if this is correct but some kind of special case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This somewhat doubled up from merging develop - should be clearer now :)

{
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);
Expand Down Expand Up @@ -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)
graham-huws marked this conversation as resolved.
Show resolved Hide resolved
index = arrayProperty.arraySize;

arrayProperty.InsertArrayElementAtIndex(index);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,6 +15,8 @@ internal class InputActionsEditorView : ViewBase<InputActionsEditorView.ViewStat
private const string autoSaveToggleId = "auto-save-toolbar-toggle";
private const string menuButtonId = "asset-menu";

private readonly TreeView m_ActionsTreeView;
private readonly ListView m_ActionMapsListView;
private readonly ToolbarMenu m_MenuButtonToolbar;
private readonly ToolbarButton m_SaveButton;

Expand Down Expand Up @@ -71,6 +74,13 @@ public InputActionsEditorView(VisualElement root, StateContainer stateContainer)
controlSchemes = controlSchemes,
selectedControlSchemeIndex = state.selectedControlSchemeIndex
});

m_ActionsTreeView = root.Q<TreeView>("actions-tree-view");
m_ActionMapsListView = root.Q<ListView>("action-maps-list-view");

root.RegisterCallback<ValidateCommandEvent>(OnValidateCommand);
root.RegisterCallback<ExecuteCommandEvent>(OnExecuteCommand);
root.focusable = true; // Required for CommandEvents to work
}

private void OnReset()
Expand Down Expand Up @@ -159,6 +169,49 @@ public class ViewState
public IEnumerable<InputControlScheme> controlSchemes;
public int selectedControlSchemeIndex;
}

void OnExecuteCommand(ExecuteCommandEvent evt)
graham-huws marked this conversation as resolved.
Show resolved Hide resolved
{
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
Expand Down