Skip to content

Conversation

@Maksims
Copy link
Collaborator

@Maksims Maksims commented Aug 6, 2025

Fixes #216 #30 #891 #520

Master ticket: #1369

This PR introduces new feature for copy/paste values between various fields.
As fields have a value type (e.g. vec3, asset[], rgba, etc) we can store such info with the value in editor's clipboard (localStorage), and provide pasting capabilities of compatible types.

This is a first iteration, it only supports clipboard when entities are selected. Assets will come a bit later.

image

@marklundin marklundin requested a review from Copilot August 6, 2025 15:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a clipboard feature for copying and pasting field values in the Inspector. The feature allows users to copy values from entity fields and paste them to compatible fields of the same type, with type validation to ensure compatibility between source and destination fields.

  • Adds a context menu with copy/paste functionality for Inspector fields
  • Implements type-aware clipboard storage using localStorage with type validation
  • Integrates clipboard functionality into the attributes inspector with contextmenu handlers

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/editor/storage/clipboard-context-menu.ts Core clipboard functionality with context menu, type validation, and copy/paste operations
src/editor/inspector/attributes-inspector.ts Integration of clipboard functionality into Inspector fields with contextmenu event handlers
src/editor/index.ts Import statement to register clipboard functionality
sass/editor/_editor-clipboard.scss Styling for clipboard context menu and field highlighting
sass/editor.scss Import for clipboard-specific styles

Comment on lines +340 to +344
domElement.classList.add('pcui-highlight-flash');
setTimeout(() => {
domElement.classList.remove('pcui-highlight-flash');
}, 250);
});
Copy link
Contributor

@willeastcott willeastcott Aug 8, 2025

Choose a reason for hiding this comment

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

PCUI has a function Element#flash but I guess some of the UI is still legacy UI....is that why you're having to do this?

Copy link
Collaborator Author

@Maksims Maksims Aug 8, 2025

Choose a reason for hiding this comment

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

They are different. Element#flash uses outline on element. While it is ok on many elements like button or input, it does not look good on LabelGroup element due to lack of padding. So pcui-highlight-flash class implements highlight with :before class with padding to better outline whole field.

Copy link
Contributor

@willeastcott willeastcott left a comment

Choose a reason for hiding this comment

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

Approving with some minor comments/feedback. Nice one!! 🚀

Copy link
Contributor

@kpal81xd kpal81xd left a comment

Choose a reason for hiding this comment

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

Overall looks good made some comments regarding styling.

As for the TODOs are these planning to be added in this PR or left for later?

this._suspendChangeEvt = false;
this._onAttributeChangeHandler = this._onAttributeChange.bind(this);

this._clipboardTypes = editor.call('clipboard:types') ?? null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Type editor call return values since type information is lost in event method

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure I actually understand this comment.
I've added above the field: _clipboardTypes: Set<string> | null;, which helps to satisfy this?

@Maksims
Copy link
Collaborator Author

Maksims commented Aug 8, 2025

TODOs will be added as subsequent PR's to keep this PR more focused. As it is already useful to the users.

@Maksims
Copy link
Collaborator Author

Maksims commented Aug 8, 2025

The newly introduced rule on linter:

326:32  error  Expected { after 'if' condition  curly

Making readability ugly.

In many cases of simple "return early", now instead of simply:

if (!item) continue;

It becomes:

if (!item) {
    continue;
}

You guys sure about that?

Specifically on this PR, this readable states:

let type = attr.type;
if (type === 'select') type = attr.args.type;
if (type === 'assets') type = 'array:asset';
if (type === 'slider') type = 'number';
if ((type === 'asset' || type === 'array:asset') && attr.args?.assetType) type += `:${attr.args.assetType}`;

Became this:

if (type === 'select') {
    type = attr.args.type;
}
if (type === 'assets') {
    type = 'array:asset';
}
if (type === 'slider') {
    type = 'number';
}
if ((type === 'asset' || type === 'array:asset') && attr.args?.assetType) {
    type += `:${attr.args.assetType}`;
}

Maybe lets focus on doing features, instead of styling and moving the code around, please?

@kpal81xd
Copy link
Contributor

kpal81xd commented Aug 8, 2025

That rule change was less 5 seconds to implement and even less time/effort to apply automatically so I do not think it takes time away from implementing features

@willeastcott
Copy link
Contributor

OK, guys - we're good to merge now? 😄

@kpal81xd
Copy link
Contributor

kpal81xd commented Aug 8, 2025

OK, guys - we're good to merge now? 😄

Yep all good from me 🫡

@willeastcott willeastcott merged commit 91d18e4 into playcanvas:main Aug 8, 2025
3 checks passed
@willeastcott
Copy link
Contributor

Let's gooOOOooooOOO!!! Merging. Thanks @Maksims!

@Maksims
Copy link
Collaborator Author

Maksims commented Aug 8, 2025

Thank you for the review!

@Maksims Maksims deleted the clipboard branch August 13, 2025 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Be able to copy component values from one Entity to another

3 participants