-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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 Copy/pasting void elements is not working #5121
Fix Copy/pasting void elements is not working #5121
Conversation
…ableTarget. Fixes Copy/pasting void elements is not working ianstormtaylor#4808
🦋 Changeset detectedLatest commit: 03234e5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this 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.
Looks fine to me... will plan to include in a release this week unless others point out something I'm missing. Thanks!
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.
Potential issue is the use case of custom copy/paste within a void element. This change probably breaks current approaches to that. Will think through this more.
…test for editing editable void
@dylans But I see the issue with copy-pasting inside the editable voids and I'm not sure how it is best to solve that 😞 Do you have any ideas? |
Looking forward to this one as it will solve some problems for our Slate use. We have a number of different void nodes that users expect to be able to Copy and Paste while the void is showing as 'selected'. I'm not sure I understand what the 'blocking' issue is… is it that you might have an |
Yes, for example in Plate, we have a void that contains an Excalidraw drawing inside it. I need time to think through how to make this not break that scenario. |
I see. I wonder if it would make sense for |
export const hasSelectableTarget = ( | ||
editor: ReactEditor, | ||
target: EventTarget | null | ||
): boolean => { | ||
return ( | ||
hasEditableTarget(editor, target) || | ||
isTargetInsideNonReadonlyVoid(editor, target) | ||
) | ||
} | ||
|
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.
@dylans
This works but the linter is not happy and I feel like I'm breaking some priciples.
Using Editor.isInline and Editor.isBlock does not work
export const hasSelectableTarget = ( | |
editor: ReactEditor, | |
target: EventTarget | null | |
): boolean => { | |
return ( | |
hasEditableTarget(editor, target) || | |
isTargetInsideNonReadonlyVoid(editor, target) | |
) | |
} | |
export const hasSelectableTarget = ( | |
editor: ReactEditor, | |
target: EventTarget | null | |
): boolean => { | |
const node = | |
hasTarget(editor, target) && ReactEditor.toSlateNode(editor, target) | |
return ( | |
hasEditableTarget(editor, target) || | |
editor.isInline(node) || | |
editor.isBlock(node) | |
) | |
} |
Hi @dylans. Have you had some time to think about this? |
I have but I don't have a good answer yet. Need a few more days to try out other examples and see the potential consequences of this. |
Definitely this. In Plate I would have added a plugin field that handles copy/paste The question here is, should we copy the void node by default? I'd say yes as it's the most common case, just note that would be a breaking change. |
This is one way I was roughly thinking could work. What do you think @laufeyrut? |
Yes, I think this could work! I don't know of a better idea. @dylans
I think being able to copy the void nodes should be the default behavior 🙏 |
Hey @laufeyrut great job on adding these fixes in place 👍 |
I really like this change, Thank you for the help @alex-vladut 🙏 @dylans I look forward to hearing what you think about this |
Description
This PR makes it possible to copy/cut void elements.
Issue
Fixes: #4808 and #4806
Example
Before
After:
Context
Created a new function hasSelectableTarget that checks if hasEditableTarget and isTargetInsideNonReadonlyVoid.
Using this function instead of hasEditableTarget so we are not excluding nonReadonlyVoids fx onCopy and onCut and onPaste
I did not add Cypress tests for the new logic since Cypress does not support copy/paste and the only solution I found was to use some package like https://www.npmjs.com/package/clipboardy. If we want to include the package or if there is a better solution for it I'm happy to add the tests.
Checks
yarn test
.yarn lint
. (Fix errors withyarn fix
.)yarn start
.)yarn changeset add
.)