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

Fix co-ordinate issue with display: contents nodes #177

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dan-cooke
Copy link

@dan-cooke dan-cooke commented Dec 10, 2024

  • I observed a bug with a custom table component I have implemented, based on prosemirror-tables . The issue arises from a conditional check in posAtCaret which will cause the position to use the doc.content.size when a zeroed out client rect is returned.

  • This commit adds an extra conditional check which will ignore any elements that have zero width and height. This seems like a sensible solution to me but please let me know if this is unwise.

Before this fix

A DOM setup like

<table>
     <tr><p>CARET</p></tr>
</table>
table {
   display: contents
}

Would incorrectly return table.posAfter from posAtCaret instead of the pos of the internal <p node

The problematic line is here

https://github.com/ProseMirror/prosemirror-view/pull/177/files#diff-8711f18f44af6275714f55277ddd18fb124ab348b03cd4b86a4fdb253b205330R241

An element with display: contents will have a zerod client bounding rect. So it will always descend into this branch.

I believe my change will handle other edge cases where an element has a zero'd bounding rects

* I observed a bug with a custom table component I have implemented,
  based on `prosemirror-tables` . The issue arises from a
  conditional check in `posAtCaret` which will cause the position to use
  the doc.content.size when a zeroed out client rect is returned.

* This commit adds an extra conditional check which will ignore any
  elements that have zero width and height. This seems like a sensible
  solution to me
@dan-cooke dan-cooke changed the title Fix co-ordinate issue with display: contents nodes Fix co-ordinate issue with display: contents nodes Dec 10, 2024
marijnh added a commit that referenced this pull request Dec 11, 2024
FIX: Fix an issue where `display: content` elements could break `posAtCoords`.

Issue #177
@marijnh
Copy link
Member

marijnh commented Dec 11, 2024

Does alternative patch bbd0ab2 solve this for you?

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

Successfully merging this pull request may close these issues.

2 participants