quill icon indicating copy to clipboard operation
quill copied to clipboard

Fix white spaces not being preserved when pasted into editor

Open luin opened this issue 1 year ago • 2 comments

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 avatar Jul 17 '24 15:07 luin

Should also fix #4108

luin avatar Jul 17 '24 15:07 luin

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

grt-mark avatar Jul 24 '24 08:07 grt-mark