slate-yjs
slate-yjs copied to clipboard
#applySlateOp doesn't properly adjust indices for move_node operations
moveNode.ts doesn't properly handle the case when the origin and the target of the move operation are under the same parent and the target node is being moved forward to a later position under the parent.
Repro:
const paragraph: Paragraph = {
type: "paragraph",
elementId: "uuid-1",
children: [
{
type: "text",
text: "",
},
{
type: "user-mention",
elementId: "uuid-2",
collaborator: {
user: "bob",
type: "user",
},
children: [{ text: "" } as any],
},
{
type: "text",
text: "abc",
},
{
type: "text",
text: "def",
bold: true,
},
],
};
describe("move inline forward", () => {
it("move inline forward", () => {
const { editor1 } = setupTreeTestEnvironment();
editor1.apply({
type: "insert_node",
node: paragraph,
path: [0],
});
editor1.flushLocalChanges();
checkSlateMatchesYjs(editor1, createTreeSlateEditor);
editor1.apply({
type: "move_node",
path: [0, 1],
newPath: [0, 3],
});
editor1.flushLocalChanges();
checkSlateMatchesYjs(editor1, createTreeSlateEditor);
});
});
Interesting find - happy to look into this in about a week. Super swamped at the moment. Glad to release a new version sooner if you put in a PR with a fix!