slate-yjs icon indicating copy to clipboard operation
slate-yjs copied to clipboard

#applySlateOp doesn't properly adjust indices for move_node operations

Open ezeidman opened this issue 2 years ago • 1 comments

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);
  });
});
Screenshot 2023-05-05 at 5 21 32 PM

ezeidman avatar May 06 '23 00:05 ezeidman

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!

BitPhinix avatar May 06 '23 17:05 BitPhinix