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

linebreakReplacement node isn't used during joinForward/joinBackward operations #1490

Closed
gpolzinatlassian opened this issue Oct 10, 2024 · 5 comments

Comments

@gpolzinatlassian
Copy link

Previously I had reported an issue (#1460) with newlines collapsing when converting code blocks to paragraphs (or other block types) when using either setBlockType or as a result of a joinForward/joinBackward operation.

The outcome of this was the introduction of the linebreakReplacement property that can be optionally applied to our hardBreak node so that it would replace newlines during these conversions instead of them being replaced by spaces.

Admittedly we've been very slow to adopt this, but I'm implementing this now in our editor and I can see that the lineBreakReplacement node is not used during joinForward or joinBackward operations that are invoked by the backpace/delete key.

Looking at the source (ProseMirror/prosemirror-transform@a0ab849) I can see that the property is only used by the setBlockType transform, whereas joinForward/joinBackward continue to invoke the clearIncompatible transform which removes newline characters, ignoring lineBreakReplacement.

Is it possible joinForward/joinBackward' can behave similarly to setBlockType on these occasions and respect the linebreakReplacement setting?

Steps to reproduce:

  1. configure an editor with the basic schema and linebreakReplacement : true enabled for the hard_break node.
  2. Add a paragraph of text, with a code node below it with multiple lines of code.
  3. Move cursor to the first position of the code node and press backspace (invoking joinBackward

Actual result:
Code is joined into the preceding paragraph with it's newlines being replaced by spaces.

Expected result:
Code is joined into the preceding paragraph with it's newlines being replaced by hard_break

@marijnh
Copy link
Member

marijnh commented Oct 10, 2024

That's a good point. Attached patch implements this.

@gpolzinatlassian
Copy link
Author

That's a good point. Attached patch implements this.

Awesome, thank you!

@gpolzinatlassian
Copy link
Author

gpolzinatlassian commented Oct 11, 2024

Hi @marijnh, sorry to be a pain but in doing some testing I think I've found an issue with this fix. The lineBreak replacement is done in the join() transform, however for joinForward/joinBackward for non-isolated nodes like this, join is invoked via joinMaybeClear here in deleteBarrier.

joinMaybeClear chains this with a clearIncompatible in front of the join (here) and clearIncompatible does it's own removal of linebreaks - replacing them with spaces, so they will be gone already before join tries to replace them.

Unrelated: there's a small spelling typo in the function name "canAppendWithSubstitutedLinebeaks"

marijnh added a commit to ProseMirror/prosemirror-transform that referenced this issue Oct 11, 2024
FIX: Allow `Transform.join` to clear incompatible inline content from the node
after the join.

Issue ProseMirror/prosemirror#1490
marijnh added a commit to ProseMirror/prosemirror-commands that referenced this issue Oct 11, 2024
…form.join

FIX: Support implicit conversion between hard break nodes and newlines in the
`joinForward` and `joinBackward` commands.

Issue ProseMirror/prosemirror#1490
@marijnh
Copy link
Member

marijnh commented Oct 11, 2024

That's a good point. Kind of awkward to arrange for these removals and replacements to be done in the correct order, so I've moved the responsibility for cleaning up inline nodes/marks into join as well, and made joinMaybeClear depend on that.

@gpolzinatlassian
Copy link
Author

Thanks! I've ran some tests and that appears to be working as expected now. 🎉

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