How to compare Prosemirror indexing and content indexing

Hello there! I have content string and formatting for it, what looks like this:

offsets: [
    {
      style: 'bold',
      start: 0,
      end: 16,
    },
    {
      style: 'italic',
      start: 4,
      end: 20,
    },
]

I want to apply this styles to the original string. But ProseMirror have different indexing system, so after i apply one style, other have shifting. How can i apply this styles exactly the same index, as orinigal string?

Thaks for your attention!

That depends on how your string is converted to a ProseMirror document.

I create EditorView instance and then manipulate it used to commands. It looks like: insert content, set selection, apply style and repeat last two steps while the array won’t end. If exist other ways to do it, I’ll happy to hear it.