-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this 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
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(); | ||
} | ||
}, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()
.
packages/lexical-utils/src/index.ts
Outdated
@@ -524,5 +524,7 @@ export function objectKlassEquals<T>( | |||
object: unknown, | |||
objectClass: ObjectKlass<T>, | |||
): boolean { | |||
return Object.getPrototypeOf(object).constructor.name === objectClass.name; | |||
return object |
There was a problem hiding this comment.
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?
return object | |
return typeof object === 'object' |
There was a problem hiding this comment.
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
.
for (const type of item.types) { | ||
const dataString = await (await item.getType(type)).text(); | ||
data.setData(type, dataString); | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Waiting on @zurfyx to approve and merge. |
This PR adds cut, copy, paste, paste as plain text and delete node options to the context menu.
Demo: