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

Fix programmatic clipboard copy on non-editable #6232

Merged
merged 7 commits into from
Jun 2, 2024
Merged

Conversation

zurfyx
Copy link
Member

@zurfyx zurfyx commented May 31, 2024

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 and blur but will do for now.

Screen.Recording.2024-05-31.at.4.50.39.PM.mov

Closes #6231

Copy link

vercel bot commented May 31, 2024

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 Jun 2, 2024 0:46am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 2, 2024 0:46am

@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 May 31, 2024
Copy link

github-actions bot commented May 31, 2024

size-limit report 📦

Path Size
lexical - cjs 23.97 KB (0%)
lexical - esm 23.96 KB (0%)
@lexical/rich-text - cjs 34.66 KB (0%)
@lexical/rich-text - esm 23.95 KB (0%)
@lexical/plain-text - cjs 34.65 KB (0%)
@lexical/plain-text - esm 225 B (0%)
@lexical/react - cjs 149.31 KB (0%)
@lexical/react - esm 82.64 KB (0%)

Comment on lines 1246 to 1247
case 'cut':
return dispatchCommand(
Copy link
Collaborator

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

@etrepum You're right 🤦‍♂️

@etrepum
Copy link
Collaborator

etrepum commented Jun 1, 2024

Looks like the current failure is prettier for packages/lexical/src/LexicalEvents.ts

case 'cut':
return dispatchCommand(
const isEditable = editor.isEditable();
switch (eventName) {
Copy link
Collaborator

@etrepum etrepum Jun 1, 2024

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.

ts playground example

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);
  }
}

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. extended-tests Run extended e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Programmatic copy fails on non-editable
4 participants