delta icon indicating copy to clipboard operation
delta copied to clipboard

Get incorrect delta by Delta.transform

Open weiQuill opened this issue 2 years ago • 1 comments

Delta package version: 4.2.2

In my use case, the results obtained by Delta.transform were not as expected.

It caused undo doesn't work as expected in the table. I suspect that in this case, the delete operation was moved to the end causing this issue. Does any have a solution? Thanks a lot:)

Before undo: image After undo: image

Expected results: image

Original delta in undo stack

{
  "ops": [
    {
      "retain": 4
    },
    {
      "retain": 1,
      "attributes": {
        "table-cell-line": {
          "row": "row-jj2vxw",
          "cell": "cell-jkfu51"
        },
      }
    },
    {
      "retain": 1,
      "attributes": {
        "table-cell-line": {
          "row": "row-pzu42n",
          "cell": "cell-5s14ao"
        },
      }
    },
    {
      "retain": 1,
      "attributes": {
        "table-cell-line": {
          "row": "row-pzu42n",
          "cell": "cell-oc2pfj"
        },
      }
    },
    {
      "retain": 1,
      "attributes": {
        "table-cell-line": null,
        "row": null,
        "cell": null,
        "rowspan": null,
        "colspan": null
      }
    },
    {
      "delete": 1
    }
  ]
}

delta for remote changes

{
  "ops": [
    {
      "retain": 7
    },
    {
      "insert": "2"
    }
  ]
}

transformed delta in undo stack

{
  "ops": [
    {
      "retain": 4
    },
    {
      "retain": 1,
      "attributes": {
        "table-cell-line": {
          "row": "row-jj2vxw",
          "cell": "cell-jkfu51"
        },
      }
    },
    {
      "retain": 1,
      "attributes": {
        "table-cell-line": {
          "row": "row-pzu42n",
          "cell": "cell-5s14ao"
        },
      }
    },
    {
      "retain": 1,
      "attributes": {
        "table-cell-line": {
          "row": "row-pzu42n",
          "cell": "cell-oc2pfj"
        },
      }
    },
    {
      "retain": 1
    },
    {
      "retain": 1,
      "attributes": {
        "table-cell-line": null,
        "row": null,
        "cell": null,
      }
    },
    {
      "delete": 1
    }
  ]
}

weiQuill avatar Dec 08 '22 08:12 weiQuill