-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Pasted plain text should inherit formatting of the surrounding text #1006
Comments
We could check if the pasted content is only text. If so, we should insert it using |
@scofalik Is it any workaround for it until you fix this issue or you are fixing it soon ? |
CKEditor 5 behaves in this case like CKEditor 4. However, what historically was a must-work-this-way solution in CKEditor 4, might be changed now in CKEditor 5. The thing is that this needs to work differently when pasting different type of content:
In CKEditor 4 we didn't have much choice with the plain text because we didn't know whether plain text was pasted or HTML which looked like plain text (had no styles). In CKEditor 5 we know this because we read the content from the clipboard. So we could, potentially, treat HTML and plain text differently. However, as I said, this is a tough call. If I copied 30 lines of plain text and pasted that somewhere where I had bold or any other style enabled... should all that be bolded? OTOH, when I copied a couple of words, applied the "code" style, pasted it I think it'd expect the pasted content to be preformatted. I guess the latter is a more common scenario, but I don't want to make a hasty decision here. Let's gather feedback, then! |
There are two workarounds I can see:
In the first one, you need to overwrite the default https://github.com/ckeditor/ckeditor5-clipboard/blob/master/src/clipboard.js#L160-L176 You basically need to copy it and modify a little. After Second solution is similar in a way that you will also add a callback to an event. This time it is So, basically, you add a callback to that event. As above, you need to check if inserted model is just a text node. If so, re-write attributes. Keep in mind that selection is given as one of arguments (the second one) so you should not get it from the Note, that the second solution may affect other features. Every feature that use |
BTW. there's one more approach -- similar to the first one I described. The difference is that you'd also need to add a callback to Refer here: https://github.com/ckeditor/ckeditor5-clipboard/blob/master/src/clipboard.js#L137-L158 In your callback, you'd have to set a flag in this fashion:
Then, use the flag to decide if |
2¢: This is a trade-off either way you slice it. Which use-case for copy/paste is more prevalent?:
Perhaps the second case is less likely, because a person copying whole paragraphs, etc will have already formatted it in another editor? Ultimately though, I think the answer will depend on the project using CKE. Maybe pick a default and allow for a project level config option? |
Quick note: Some desktop editors have multiple options of pasting -- paste as copied, paste unformatted, etc. |
We hoped to implement such a feature in the past, but it's not an easy feature due to its UX. |
$0.02 I juts looked at how pasting works and confirm that using CKEditor 4CKEditor 5My intuition as an end user is that whenever I paste any portion of a content as plain text I expect it to be formatted exactly in the same way as the place where I'm pasting it. |
I think it's ok if we change the current behavior. That's even a bit of logic that could be configurable ( Ideally, the user should be able to decide how the content should be pasted. The dropdown (displayed after a past happened) with multiple options is something that we should consider long-term. Short-term, we need to tune the automatic behavior. |
I wonder if we should differentiate between:
The former means that the user intentionally chose plain-text. The latter is more accidental. WDYT? |
We could detect shift+ctrl+v either by listening or just by checking for sole Because of the editor configuration there is one case that is tricky: pasting unsupported format. It would end up as plain text in the model. I'd go with PR's implementation to unify behaviour for all of this and remove this one use-case. More on this: #7778 (comment). |
Feature (clipboard): Pasting a plain text will inherit selection attributes. Closes #1006.
Is this a bug report or feature request? (choose one)
🐞 Bug report
💻 Version of CKEditor
1.0.0.beta.2
📋 Steps to reproduce
✅ Expected result
The new text should be Bold as well.
❎ Actual result
The new text is not Bold.
📃 Other details that might be useful
The text was updated successfully, but these errors were encountered: