ckeditor / ckeditor5

Powerful rich text editor framework with a modular architecture, modern integrations, and features like collaborative editing.
https://ckeditor.com/ckeditor-5
Other
9.45k stars 3.69k forks source link

An editor with GHS and Font plugins will split a singular span into two separate ones #16120

Open mabryl opened 6 months ago

mabryl commented 6 months ago

๐Ÿ“ Provide detailed reproduction steps (if any)

  1. Pick an editor build that contains GHS, FontColor and FontBackroundColor
  2. Provide the following HTML to the editor: <span custom-attribute="foo" style="background:red; color:green;">test</span>
  3. See how the data changes once it's inserted into the editor

โœ”๏ธ Expected result

In an editor build that contains just GHS, the singular span is retained:

image

โŒ Actual result

Once you include FontColor and FontBackgroundColor in the editor, these plugins will take precedence over GHS and a second span will be inserted:

image

โ“ Possible solution

This is only reproducible if there's something non-standard in the data that GHS needs to handle separately. In the example above, the issue is not reproducible if your remove custom-attribute="foo" from the original data.

Possibly related to https://github.com/ckeditor/ckeditor5/issues/15757

๐Ÿ“ƒ Other details


If you'd like to see this fixed sooner, add a ๐Ÿ‘ reaction to this post.

Witoso commented 6 months ago

@niegowski I assume this is expected after our changes (and is a โ€œwon't fixโ€ on our side). We fixed the bug, and background is consumed properly by the Font plugin (and will be handled by this plugin in the UI), and custom-attribute is handled by GHS. Therefore, the engine correctly outputs two span's.

niegowski commented 6 months ago

@niegowski I assume this is expected after our changes (and is a โ€œwon't fixโ€ on our side). We fixed the bug, and background is consumed properly by the Font plugin (and will be handled by this plugin in the UI), and custom-attribute is handled by GHS. Therefore, the engine correctly outputs two span's.

This is unrelated to the recent fix for background. It can be reproduced with code as simple as <span custom-attribute="foo" style="color:green;">test</span>. This is related to the view AttributeElement priority. These spans could get merged into a single span but those features generate AttributeElements at different priorities and this makes it non-mergeable. The font color feature uses priority 7 and the generic GHS span uses the default 10. I'm not sure why we use different priorities for font features. We use 5 for links because they should not get split in HTML if we have part of it formatted, for example, bolded.

Reinmar commented 6 months ago

As far, we pull the font styles out to prevent situations like this one: https://jsfiddle.net/Lcjzntkd/

image
Witoso commented 6 months ago

Rel: https://github.com/ckeditor/ckeditor5/issues/2291