Decoration Mapping Issues After Inline Replacements

After a selection change, I see an extra step in my transaction, which is causing issues with decoration positioning.

In the following HTML, I highlighted the "23":

<p>
  <strong>
    <span inputsource="AREA_TYPED_TEXT">1-2</span>
  </strong>
  <reporting-field-start class="reporting-field"></reporting-field-start>
  <span inputsource="AREA_TYPED_TEXT">
    <span class="reporting-field">3-4</span>
  </span>
</p>

Then I ran:

const newSet = oldStateDecoration.map(tr.mapping, tr.doc);

The tr.steps looks like this:

[
  {
    "stepType": "replace",
    "from": 14,
    "to": 19,
    "slice": {
      "content": [
        {
          "type": "text",
          "marks": [
            { "type": "strong" },
            { "type": "colorCoding", "attrs": { "inputSource": "AREA_TYPED_TEXT" } }
          ],
          "text": "x"
        },
        {
          "type": "text",
          "marks": [
            {
              "type": "style",
              "attrs": {
                "style": null,
                "class": null,
                "id": null
              }
            }
          ],
          "text": "-4"
        }
      ]
    }
  }
]

But I only highlighted 2 characters ("23"), so why is the mapping showing:

{
  "maps": [
    {
      "ranges": [14, 5, 3],
      "inverted": false
    }
  ]
}

A selection change shouldn’t produce any steps. What, precisely, are you doing to create this transaction?

I don’t see the number 23 in this piece of HTML.

The code when inserted into an empty html file looks like this: 1-2 3-4

So I guess he is dragging over the two middle numbers?

Thank you for your reply.

I typed x after selection. Below is an example of the editor view.

chrome-capture-2025-10-24 (1)

The [ position depends on the decoration’s position after the map, and it gets pushed to the end of the background mark.

Okay, I see. It probably shouldn’t do that. Can you set up a minimal reproduction script that demonstrates this?

Got it, I’ll try to put together a minimal reproduction script. It might take me a bit of time, but I’ll share it once I have something that demonstrates the issue.

We fixed the issue it was a misconfigured markSpec.

@marijn thank you for the help :slight_smile: