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

Dropping text in front of a table produces a broken table #1506

Closed
mr1name opened this issue Jan 31, 2025 · 3 comments
Closed

Dropping text in front of a table produces a broken table #1506

mr1name opened this issue Jan 31, 2025 · 3 comments

Comments

@mr1name
Copy link

mr1name commented Jan 31, 2025

When dropping text, prosemirror attempts to calculate the insert position via posAtCoords. In this case, it uses the element's bounding box. So if the cursor gets there, rather than adjusting the position, it assumes that the insertion occurs at the depth level of the table rows and looks for suitable neighbors for the new element and finds tableRow.

A table that is created in this way is invisible and broken. It cannot be deleted via Backspace (throws error), properly selected, etc. To reproduce this, just go to any prosemirror example with tables. For example, tiptap or prosemirror-tables demo. https://prosemirror-tables.netlify.app/

From my understanding the problem is in the core prosemirror logic and is not related directly to tables or any integrations. And it is probably much more general, so tables are just one of the scenarios.

Screen.Recording.2025-01-31.at.11.47.52.mov
@marijnh
Copy link
Member

marijnh commented Jan 31, 2025

I would say the problem is related to the table code. It defines a table row as having zero or more children (which is needed because due to rowspans, you can have valid tables with empty rows), so when a table row is cut in two by dropped content, the ProseMirror core decides that leaving a table with an empty row in front of the dropped content should be fine. The appropriate solution would probably be to have the table-fixing code in prosemirror-tables/src/fixtables.js, which currently only ensures tables are rectangular, also check for empty tables and delete them.

@mr1name
Copy link
Author

mr1name commented Jan 31, 2025

@marijnh That's pretty much how we fixed it for ourselves. I just felt like it was a hack and not a proper solution.
hcengineering/platform#7848

If you think this is the most suitable option, I may also integrate this logic into tableFixer via PR.

@mr1name mr1name changed the title Dropping text in front of a table produces a broken table (the problem is not related to the table plugin itself) Dropping text in front of a table produces a broken table Jan 31, 2025
@marijnh
Copy link
Member

marijnh commented Feb 4, 2025

I don't maintain prosemirror-tables , but I'd say this is a bug, and a PR that addresses it would probably be welcome there.

@marijnh marijnh closed this as completed Feb 4, 2025
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