-
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
Fix programmatic clipboard copy on non-editable #6232
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
case 'cut': | ||
return dispatchCommand( |
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.
Shouldn't cut also be conditional when isEditable
?
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.
@etrepum You're right 🤦♂️
Looks like the current failure is prettier for packages/lexical/src/LexicalEvents.ts |
case 'cut': | ||
return dispatchCommand( | ||
const isEditable = editor.isEditable(); | ||
switch (eventName) { |
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.
Do you think this would be easier to maintain as a table? e.g.
const READONLY_EVENTS = {
copy: COPY_COMMAND,
// more commands here
} as const;
const EDITABLE_EVENTS = {
...READONLY_EVENTS,
cut: CUT_COMMAND,
// more commands here
} as const;
export function dispatchEvent(editor: LexicalEditor, eventName: string, event: Event) {
const eventMap = editor.isEditable() ? EDITABLE_EVENTS : READONLY_EVENTS;
const command = (eventMap as Readonly<Record<string, undefined | LexicalCommand<Event>>>)[eventName];
if (command) {
dispatchCommand(editor, command, event);
}
}
Clipboard copy uses a double execCommand hack. It turns out that we weren't listening for the copy event on non-editable. This PR allowlists this event which will subsequently dispatch the command after, I think this list should be revised after, potentially adding
focus
andblur
but will do for now.Screen.Recording.2024-05-31.at.4.50.39.PM.mov
Closes #6231