Skip to content

#applySlateOp doesn't properly adjust indices for move_node operations #391

@ezeidman

Description

@ezeidman

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions