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

Bug: Copying (cmd+c) doesn't work properly when editable is false #4446

Closed
SamCB-CT opened this issue May 3, 2023 · 2 comments
Closed

Bug: Copying (cmd+c) doesn't work properly when editable is false #4446

SamCB-CT opened this issue May 3, 2023 · 2 comments
Labels

Comments

@SamCB-CT
Copy link

SamCB-CT commented May 3, 2023

Lexical version: 0.9.1

Steps To Reproduce

As per the codesandbox example below:

  1. Have a node set to editable, the other without it
  2. Optionally, a custom node with getTextContent() overwritten so you can see plaintext changes.
  3. Copy from the text field
  4. Paste into a clipboard inspector (such as: https://evercoder.github.io/clipboard-inspector/)

Link to code example:

https://codesandbox.io/s/quizzical-tristan-o459jr?file=/src/App.tsx

The current behavior

Copying from the enabled editor, paste into the clipboard inspector will result in:

text/plain:  A VALUE THAT WILL BE UPPERCASE WHEN COPIED.
text/html:   <meta charset='utf-8'><span>A value that will be uppercase when copied.</span>
application/x-lexical-editor:
             {"namespace":"MyEditor","nodes":[{"detail":0,"format":0,"mode":"normal","style":"","text":"A value that will be uppercase when copied.","type":"shouting-text","version":1}]}

Copying from the editor with editable set to false will only copy the actual value from within the div box, no reformatting, no custom clipboard behaviour.

text/plain:  But this will not be uppercase when copied.
text/html:   <meta charset='utf-8'><div id="root" style="color: rgb(0, 0, 0); font-family: Times; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="App" style="font-family: sans-serif; line-height: 2rem;"><div aria-autocomplete="none" contenteditable="false" spellcheck="true" data-lexical-editor="true" style="user-select: text; white-space: pre-wrap; word-break: break-word;"><p class="editor-paragraph ltr" dir="ltr" style="text-align: left; margin: 0px 0px 15px; position: relative;"><span data-lexical-text="true">But this will not be uppercase when copied.</span></p></div></div></div>

The expected behavior

Copying from the editor, regardless of setting, results in the appropriate formatting and custom clipboard behaviour:

text/plain:  A VALUE THAT WILL BE UPPERCASE WHEN COPIED.
text/html:   <meta charset='utf-8'><span>A value that will be uppercase when copied.</span>
application/x-lexical-editor:
             {"namespace":"MyEditor","nodes":[{"detail":0,"format":0,"mode":"normal","style":"","text":"A value that will be uppercase when copied.","type":"shouting-text","version":1}]}

Exploration

According to:

case 'copy':
return dispatchCommand(
editor,
COPY_COMMAND,
event as ClipboardEvent,
);

It appears to be that the copy event is only dispatched when editing is enabled. While it probably makes sense that most events are disabled, I'd imagine that copy is a reasonably safe exception to that rule?

@acywatson
Copy link
Contributor

Yea, I think it is a safe exception. Unfortunately there's not a pre-existing pattern for registering some of those events when editable is false, so we'll need to build that path.

@acywatson acywatson added copy+paste Relates to Lexical Copy/Paste help-wanted labels May 4, 2023
@etrepum
Copy link
Collaborator

etrepum commented Dec 8, 2024

As far as I can tell this is fixed, the isEditable condition is lifted to individual events. For example, it will stop a cut or paste but not a copy. #6232

@etrepum etrepum closed this as completed Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants