Skip to content

Path related issue with inverted operations #1

Open
@manufacturist

Description

@manufacturist

Hey @kbadk,

The issue I am having is with lines 87-90. The code works fine for every other scenario I've tested, however when trying to apply inverted operations it simply does not work because of the final path value change done at those lines.

Let's look at the following scenario. I want to bold the 'b' letter in the following HTML:

<body>
  <p>abc</p>
</body>

Obtaining:

<body>
  <p>a<strong>b</strong>c</p>
</body>

I'm doing this by running the json0-ot-diff code in the browser and retrieving the diffs between an older version of the JsonML (obtained from the body element) and the newer one (after the bold operation).

The following operations are obtained:

  1. {p:[2,2], ld:"abc", li:"a"} - Ok
  2. {p:[2,3], li: ["STRONG", {}, "b"]} - Ok
  3. {p:[2,5], li: "c"} - Why?

The inverted ops are the following (applied in this exact order):

  1. {p:[2,5], ld: "c"} - Will not apply correctly using the json0.apply(snapshot, op) function because there is nothing at path [2,5]
  2. {p:[2,3], ld: ["STRONG", {}, "b"]} - Ok
  3. {p:[2,2], ld:"a", ld:"abc"} - Ok

What is the reason for increasing / decreasing the final element of the path array by 1 for 'li' / 'ld' operations when if (equal(path, opParentPath))?

EDIT 1:
I've just understood the logic of the code, however I still think that there's a bug regarding the scenario above.

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