Rebasing does not work on a very basic example
Author: mitarCreated Nov 23, 2018Updated Apr 7, 2026
Issue details
When trying to rebase three sets of steps (initial, fork1 which adds at the end, fork2 which replaces at the beginning), rebasing drops content from fork2, instead of combining those steps together.
Steps to reproduce
const {rebaseSteps} = require('prosemirror-collab');
const {Step, Transform} = require('prosemirror-transform');
const {Schema} = require('prosemirror-model');
const nodes = {
doc: {
content: 'title (paragraph|block)+',
},
title: {
content: 'inline*',
parseDOM: [{
tag: 'h1',
}],
toDOM(node) {
return ['h1', 0];
},
},
paragraph: {
content: 'inline*',
group: 'block',
parseDOM: [{
tag: 'p',
}],
toDOM(node) {
return ['p', 0];
},
},
text: {
group: 'inline',
},
};
const marks = {};
const schema = new Schema({nodes, marks});
const INITIAL_STEPS = [{
stepType: 'replace',
from: 3,
to: 3,
slice: {
content: [{
type: 'text',
text: 't',
}],
},
}, {
stepType: 'replace',
from: 4,
to: 4,
slice: {
content: [{
type: 'text',
text: 'e',
}],
},
}, {
stepType: 'replace',
from: 5,
to: 5,
slice: {
content: [{
type: 'text',
text: 's',
}],
},
}, {
stepType: 'replace',
from: 6,
to: 6,
slice: {
content: [{
type: 'text',
text: 't',
}],
},
}];
const FORK1_STEPS = [{
stepType: 'replace',
from: 7,
to: 7,
slice: {
content: [{
type: 'text',
text: '.',
}],
},
}];
const FORK2_STEPS = [{
stepType: 'replace',
from: 3,
to: 4,
slice: {
content: [{
type: 'text',
text: 'T',
}],
},
}];
const doc = schema.topNodeType.createAndFill();
const transform = new Transform(doc);
const initialSteps = [];
for (const step of INITIAL_STEPS) {
initialSteps.push(Step.fromJSON(schema, step));
transform.step(initialSteps[initialSteps.length - 1]);
}
const fork2steps = [];
for (const step of FORK2_STEPS) {
fork2steps.push(Step.fromJSON(schema, step));
transform.step(fork2steps[fork2steps.length - 1]);
}
const fork1steps = [];
for (const step of FORK1_STEPS) {
fork1steps.push(Step.fromJSON(schema, step));
}
rebaseSteps(fork2steps.map((s, i) => {
return {
step: s,
inverted: s.invert(transform.docs[initialSteps.length + i]),
};
}), fork1steps, transform);
console.log(transform.doc.toJSON().content[1]);I would expect the output to be text Test. and not test. which I get when running the script above. So only appending . is preserved, but the change at the beginning from t to T is not. If I instrument rebaseSteps function and add some prints to the console, I can see that the step to convert t to T is not mapped (mapped is null).
ProseMirror version
"prosemirror-collab": "~1.1.1",Source: ProseMirror/prosemirror