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 white spaces not being preserved when pasted into editor #4319

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

luin
Copy link
Member

@luin luin commented Jul 17, 2024

Bug addressed by this PR:

  1. Go to https://quilljs.com/playground/snow
  2. Type "1 2" (note the consecutive spaces in the middle)
  3. Select all text in the editor
  4. Copy and paste

Expected: content doesn't change
Actual: content becomes "1 2". Only one space in the middle.


This PR fixed the issue with two changes:

  1. Quill#getSemanticHTML() now exports white-space style when white spaces may be collapsed. E.g. with this PR, the output html of the about content would become <span style="white-space: pre-wrap">1 2</span> instead of just 1 2. This change makes sure that we provide enough information to the target application where the content is pasted into. E.g. before this PR, pasting the above content to Google Docs will lose the spaces.

  2. Clipboard#convert() now respects white-space style besides pre tag. Browsers and applications (e.g. Google Docs) may add white-space style for elements that need to preserve whitespaces. Before this change, spaces will be collapsed in Clipboard#convert(). To test:

    1. Type "hello world" into Google Docs
    2. Copy all text from Google Docs
    3. Paste into a Quill editor
    4. Make sure spaces between the two words are preserved

@luin
Copy link
Member Author

luin commented Jul 17, 2024

Should also fix #4108

@luin luin requested a review from jhchen July 17, 2024 15:51
@luin luin force-pushed the zh-white-space branch 2 times, most recently from 86bbfd0 to 87967e6 Compare July 18, 2024 06:31
@grt-mark
Copy link

Is this the issue where the leading white space inside of my html p tag is not being preserved when using quill.clipboard.convert. Cuz this is the issue that im facing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants