Skip to content

Conversation

@karwosts
Copy link
Member

Proposed change

When using Ctrl-C + Ctrl-V to copy/paste a sequence building block inside a script, the paste action does not paste the sequence, but instead cracks it and pastes the individual items, but not the building block.

This is because

sequence:
  - action: ...

is ambiguous, it could be a script with one action, or it could be a building block element inside a script with one action.

To fix this to behave as expected, when we copy a sequence building block in the visual editor, we can use metadata to differentiate that it is a building block and not a complete script. So we will put on the clipboard:

sequence:
  - action: ...
metadata: {}

Then in handlePaste, if we detect a sequence with metadata, we know for sure that it is a building block and can do the paste correctly.

This was almost fully clean solution, except that if you Ctrl-C this and paste it in yaml, it is unsaveable, because core will reject a sequence with a metadata object. So I make a core change as well to allow metadata on a sequence building block, same as how we allow it for actions. We will generally clean this up and remove it when normalizing, but we don't currently normalize a script before saving it, so it isn't caught if you just paste this and save.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

@arturpragacz
Copy link

As an alternative we could consider migrating scripts to use actions at the top level, just as automations already do.

@karwosts
Copy link
Member Author

As an alternative we could consider migrating scripts to use actions at the top level, just as automations already do.

Even if you do that, and then treat a sequence paste as always a building-block, there is still a large collection of scripts out there with the legacy syntax, and pasting those would no longer behave as originally intended. Not necessarily a deal breaker, but just something to consider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copy / Paste not working with Sequence inside Scripts

3 participants