Skip to content

Commit

Permalink
Avoid preventing default for copy events when there is no selection (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm authored and thegreatercurve committed Nov 25, 2022
1 parent 6bdceef commit bc3c492
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions packages/lexical-plain-text/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,20 @@ function onCopyForPlainText(
event: CommandPayloadType<typeof COPY_COMMAND>,
editor: LexicalEditor,
): void {
event.preventDefault();
editor.update(() => {
const clipboardData =
event instanceof KeyboardEvent ? null : event.clipboardData;
const selection = $getSelection();

if (selection !== null) {
if (clipboardData != null) {
const htmlString = $getHtmlContent(editor);

if (htmlString !== null) {
clipboardData.setData('text/html', htmlString);
}
if (selection !== null && clipboardData != null) {
event.preventDefault();
const htmlString = $getHtmlContent(editor);

clipboardData.setData('text/plain', selection.getTextContent());
if (htmlString !== null) {
clipboardData.setData('text/html', htmlString);
}

clipboardData.setData('text/plain', selection.getTextContent());
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/lexical-rich-text/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,9 @@ function onCopyForRichText(
event: CommandPayloadType<typeof COPY_COMMAND>,
editor: LexicalEditor,
): void {
event.preventDefault();
const selection = $getSelection();
if (selection !== null) {
event.preventDefault();
const clipboardData =
event instanceof KeyboardEvent ? null : event.clipboardData;
const htmlString = $getHtmlContent(editor);
Expand Down

0 comments on commit bc3c492

Please sign in to comment.