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

Why there is a <br> in the ProseMirror view by default? #117

Closed
caocanx opened this issue Mar 7, 2024 · 7 comments
Closed

Why there is a <br> in the ProseMirror view by default? #117

caocanx opened this issue Mar 7, 2024 · 7 comments

Comments

@caocanx
Copy link
Contributor

caocanx commented Mar 7, 2024

<div contenteditable="true" translate="no" class="ProseMirror">
    <br class="ProseMirror-trailingBreak">
</div>
@smoores-dev
Copy link
Collaborator

This is the default ProseMirror behavior: https://discuss.prosemirror.net/t/new-nodes-without-br/865/2

Those are there because, due to historic accident, browsers expect them to be there in empty editable elements, or they won’t show the element at all. They are not part of your actual document, so you don’t need to worry about them.

@caocanx
Copy link
Contributor Author

caocanx commented Mar 7, 2024

This is the default ProseMirror behavior: https://discuss.prosemirror.net/t/new-nodes-without-br/865/2

Those are there because, due to historic accident, browsers expect them to be there in empty editable elements, or they won’t show the element at all. They are not part of your actual document, so you don’t need to worry about them.

Thanks for your reply. But I still have a question, today we can return a <div contentEditable></div> in react and the browser can just render it without a <br> inside. And I saw that discussion in the link is about 7 years ago, so I think is there a way to fix it now?

@caocanx
Copy link
Contributor Author

caocanx commented Mar 7, 2024

This is the default ProseMirror behavior: https://discuss.prosemirror.net/t/new-nodes-without-br/865/2

Those are there because, due to historic accident, browsers expect them to be there in empty editable elements, or they won’t show the element at all. They are not part of your actual document, so you don’t need to worry about them.

Thanks for your reply. But I still have a question, today we can return a <div contentEditable></div> in react and the browser can just render it without a <br> inside. And I saw that discussion in the link is about 7 years ago, so I think is there a way to fix it now?

I find there is still have a <br> inside after click the <div contentEditable></div>, but before click it not have the <br>.

@smoores-dev
Copy link
Collaborator

It's a fair question! I think this conversation is probably better suited for the ProseMirror forum; I'm less familiar with the nuances of contentEditable support in browsers, and this library aims to have identical behavior to ProseMirror wherever possible.

@caocanx
Copy link
Contributor Author

caocanx commented Mar 7, 2024

It's a fair question! I think this conversation is probably better suited for the ProseMirror forum; I'm less familiar with the nuances of contentEditable support in browsers, and this library aims to have identical behavior to ProseMirror wherever possible.

You are right, we should discuss there.

@smoores-dev
Copy link
Collaborator

smoores-dev commented Mar 15, 2024

@caocanx in case you're still interested, I actually had to add these trailing <br> (and <img>!) hacks in even more places (#122, matching prosemirror-view's behavior) to resolve selection bugs in Chrome, Safari, and Firefox! These are definitely still necessary and relevant to allow users to place cursors within empty text blocks, as well as at the end of text blocks whose last child nodes are atoms or are not contenteditable!

@caocanx
Copy link
Contributor Author

caocanx commented Mar 15, 2024

@smoores-dev thanks for your information. Very useful! 👍

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

No branches or pull requests

2 participants