I’ve you’ve ever glanced into prosemirror-transform/src/replace.js, you’ve probably noticed the horrors of complexity that lurked in the step-fitting algorithm. I was recently looking into a problem with the code that I just didn’t manage to solve in the old codebase.
So I rewrote it, and the result is a lot easier to work with. But because this is still a subtle, tricky algorithm, I am a bit nervous about just assuming my new code is correct because the tests pass. If you have a custom schema and a bunch of automated tests, I’d be very grateful if you could run them with prosemirror-transform version 1.2.5-beta1 and let me know if you find any problems.
If no problems are found, I’ll tag this as a regular release in two weeks or so.
We tested 1.2.5-beta1 on nextjournal and it’s looking good, thank you a lot!
With that version pasting open slices ending with lists in our title node now works, but we’re still incurring in a paste issue with our custom schema, namely code nodes:
...
:code {:attrs {:id {:default nil}
:collapsed {:default false}}
:content "inline*"
:group "block"
:marks ""
;; setting `code` to false to avoid being handled as plain text for copy & paste, see
;; https://github.com/ProseMirror/prosemirror-view/blob/d5f05ac6b99a417ab7faa7d31622b4c9b0a6fa03/src/clipboard.js#L39
:code false
:defining true
:isolating true
...
Copying slices which start with a title and end with a code node are still not pasteable into a title. I will try to reproduce in a minimal schema based on the default one, but maybe in the meanwhile this rings the bell to you already…
Is this a regression or something that didn’t work before either? There are limits to what the fitting algorithm can do—inserting something before a title, if the schema only allows one title, might just be impossible. But if you think there’s a reasonable behavior that’s failing to happen, and you have an example, do open an issue.
didn’t work before either. The scenario I’m referring to is a slice with a Title + contents + a final code node pasted into an empty document into the empty title placeholder. I’ll try to reproduce in a basic example.
I don’t know if this can help you, but I added the beta version as a resolution for prosemirror-transform in atlaskit repo. This is the environment (we are not up to date):
Test Suites: 2 failed, 272 passed, 274 total
Tests: 24 failed, 68 skipped, 3557 passed, 3649 total
These are the error this time:
It looks that our own gap cursor implementation is not working anymore (6 from 24)
Expected specified selections to match in both values.
403 | expect(
404 | editorInstance.editorView.state,
> 405 | ).toEqualDocumentAndSelection(
| ^
406 | doc(panel()(p('onetwo'), p('three ')), hr(), '{<|gap>}'),
407 | );
408 | });
There is a recurrent error happening is a bit hard to explain. It’s happening within our insert nodes tests, I will try to share enough information. (18 from 24).
All the failing test are caused when you try to add a node in an invalid parent, with the beta version is adding the node in the wrong position.
Some times add an empty paragraph at the end for no reason.
Other times inject the node in the wrong position.
// Test
it('start of paragraph', () => {
const { editorView } = editor(doc(panel()(p('{<>}onetwo'))));
insertDummyMedia(editorView);
expect(editorView.state.doc).toEqualDocument(
doc(
mediaSingle({ layout: 'center' })(
temporaryMediaWithDimensions(),
),
panel()(p('onetwo')),
),
);
});
// Output
// Inject the media after the paragraph node instead of before the paragraph.
// And add an empty paragraph at the end
// Like:
doc(
panel()(p('onetwo')),
mediaSingle({ layout: 'center' })(
temporaryMediaWithDimensions(),
),
p('')
)
Also, there is a case where the node get replaced at all
Thanks for the feedback. Could you tell a bit more about your schema and the actual Transform methods these tests end up calling? I am having trouble interpreting these results.
I looked through the relevant code, and this is indeed pretty deep—too deep for me to be able to derive a matching test case from it (I tried a bunch of possibilities, but none show behavior similar to the failure you are showing. I couldn’t get the tests to run at all locally.)
to be fair our code is to complex and we are a couple of minor versions behind. If you could not reproduce maybe it is related to some of the other minors.
I might try to debug it tomorrow, but I don’t think I will have time tbh .