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

Context Menu Options Added #4713

Merged
merged 5 commits into from
Jul 3, 2023
Merged

Conversation

Shubhankerism
Copy link
Collaborator

This PR adds cut, copy, paste, paste as plain text and delete node options to the context menu.

Demo:
context-menu

@vercel
Copy link

vercel bot commented Jun 27, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2023 8:51am
lexical-playground ❌ Failed (Inspect) Jul 3, 2023 8:51am

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 27, 2023
@Shubhankerism Shubhankerism requested a review from ivailop7 June 27, 2023 17:12
Copy link
Member

@zurfyx zurfyx left a comment

Choose a reason for hiding this comment

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

Looking great, thanks for working on this! Adding some minor comments

Comment on lines 173 to 184
new ContextMenuOption(`Delete Node`, {
onSelect: (_node) => {
const selection = $getSelection();
if ($isRangeSelection(selection)) {
const currentNode = selection.anchor.getNode();

const parentNode = $findMatchingParent(currentNode, (node) => {
return node.__parent === 'root';
});
parentNode?.remove();
}
},
Copy link
Member

Choose a reason for hiding this comment

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

Will this work for ImageNode which is an inline node? I presume that in this case it will still delete the entire paragraph?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi, thanks for the review! :)
Yes, it will delete the entire paragraph, the current logic removes the node that has root as its parent.

const currentNode = selection.anchor.getNode();

const parentNode = $findMatchingParent(currentNode, (node) => {
return node.__parent === 'root';
Copy link
Member

Choose a reason for hiding this comment

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

Nit; I would try to avoid the use of private properties beyond the core, so I'd probably use a combination of getParent and $isRootNode in this case. It's not the most performant but it's the recommended consumer-wise

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have updated the logic to now use getParents().

@@ -524,5 +524,7 @@ export function objectKlassEquals<T>(
object: unknown,
objectClass: ObjectKlass<T>,
): boolean {
return Object.getPrototypeOf(object).constructor.name === objectClass.name;
return object
Copy link
Member

Choose a reason for hiding this comment

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

I presume you're checking null values here. Can we use triple equality?

Suggested change
return object
return typeof object === 'object'

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using object !== null as typeof null returned object.

Comment on lines +136 to +139
for (const type of item.types) {
const dataString = await (await item.getType(type)).text();
data.setData(type, dataString);
}
Copy link
Member

Choose a reason for hiding this comment

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

Does this cover images? Can also be done in a follow-up PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I am able to copy paste images as well, the only case where it doesn't seem to work is when I try to copy paste the sample image that's provided when we try to upload an image. Will investigate this and do a follow up PR.

Copy link
Collaborator

@ivailop7 ivailop7 left a comment

Choose a reason for hiding this comment

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

LGTM

@ivailop7
Copy link
Collaborator

ivailop7 commented Jul 3, 2023

Waiting on @zurfyx to approve and merge.

@zurfyx zurfyx merged commit f2da28a into facebook:main Jul 3, 2023
@Shubhankerism Shubhankerism deleted the context-menu-options branch July 3, 2023 13:24
@zurfyx zurfyx mentioned this pull request Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants