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

Writer fields with inline: true only store first paragraph when multiple are pasted #4310

Closed
crisgraphics opened this issue May 19, 2022 · 13 comments · Fixed by #4351
Closed
Assignees
Labels
type: bug 🐛 Is a bug; fixes a bug
Milestone

Comments

@crisgraphics
Copy link

Description

First off, sorry if someone posted this already, I couldn't find it.
If I paste something from MS Word into the writer field, only the first paragraph gets saved.

Screenshots

kirby_writerfield_issue.mp4

To reproduce

  1. Go to About Us page of the starter kit
  2. paste something from MS Word into the address field
  3. Hit save
  4. Reload

Kirby Version
3.6.6

Your system (please complete the following information)
Tested with:

  • Mac OSX 11.6.4, Firefox latest
  • Windows 10, MS Edge latest
@lukasbestle
Copy link
Member

Thanks for the detailed issue description. 👍

The writer field from your example uses the inline mode, which only supports one paragraph. Does it work for you if you remove the inline property?

@lukasbestle lukasbestle added the needs: information ❓ Requires more information to proceed label May 19, 2022
@crisgraphics
Copy link
Author

Thanks Lukas!
It works fine when I'm turning off the inline mode.
However it's still a bit confusing to see the whole text getting pasted when only the first paragraph gets saved in the end.
My client has made changes to quite a couple of fields already when he first noticed, that some content is missing.
But now that I know, I guess it's my part to take care of that.

@lukasbestle
Copy link
Member

I agree, the current behavior is quite confusing.

Issue Summary

Status quo

If the user gets the Editor to contain multiple paragraphs (for example by pasting formatted content), a writer field with inline: true will only store the first paragraph and ignore the rest.

Source of the issue

I think the issue is caused by this line:

return div.querySelector("p").innerHTML;

It just takes the contents of the first <p> element and ignores the rest.

Possible solution

We could instead use querySelectorAll('p') and concat the contents of all matched elements. Between the paragraphs, a <br> should be inserted (maybe even two?).

@lukasbestle lukasbestle added type: bug 🐛 Is a bug; fixes a bug and removed needs: information ❓ Requires more information to proceed labels May 20, 2022
@lukasbestle lukasbestle changed the title Copy Paste from MS Word into writer field only stores the first paragraph Writer fields with inline: true only store first paragraph when multiple are pasted May 20, 2022
@distantnative
Copy link
Member

Isn't that quite negating the purpose of inline then? I'd think you get one line from this, not faked paragraphs via breaks. So not sure that's reducing confusion, rather shifting it.

@lukasbestle
Copy link
Member

You can already enter multiple lines in an inline writer and it will also generate hard breaks instead of paragraphs. So it would only be consistent if the same happens on paste.

@lukasbestle
Copy link
Member

Thinking about it again: I think the conversion should already happen on paste, not on export. This way the UI won't jump on save/reload.

@afbora
Copy link
Member

afbora commented Jun 11, 2022

We could instead use querySelectorAll('p') and concat the contents of all matched elements. Between the paragraphs, a
should be inserted.

@lukasbestle This solution works great. After the paragraphs are converted to <br> and the page is refreshed, the savebar does not appear when pasting the same text again. Do you want me to create a PR for your solution?

@lukasbestle
Copy link
Member

@afbora Yes, that would be great. Bonus points if you find a way to do the conversion on paste. :)

@afbora
Copy link
Member

afbora commented Jun 11, 2022

find a way to do the conversion on paste. :)

Do you mean instant conversion (paragraphs to breaks) on paste, not after save, right?

@lukasbestle
Copy link
Member

If the writer field has inline mode activated, yes. :)

@afbora
Copy link
Member

afbora commented Jun 12, 2022

@lukasbestle I've two solutions (Only one of them needs to be merged). But I couldn't find a way to conversation on paste.

@lukasbestle
Copy link
Member

Thanks! To be honest I don't have enough knowledge of the writer and ProseMirror to review which of the options is best or if there's another possible implementation. @bastianallgeier?

@bastianallgeier
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Is a bug; fixes a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants