Finding resolved offsets from plain text

Hello, i would like to ask for help with resolving element position. I’m quite new to this editor and haven’t find the solution in documentation. Is there a way to find resolved positions based on absolute position from plain text string?

I have a text editor and i need some logic to be done on backend. For example i send a text from my editor to the backend (using editor.getText()) and receive a response with

  • a phrase that i want to highlight with mark
  • starting/ending text positions of this phrase relative to the whole text.

But the problem is that these offsets are different from the resolved positions for this phrase in editor.

Is there any solution other than writing a custom function to iterate through all the nodes and resolving the position myself?

There’s no getText method in this library, so I’m not sure what kind of text conversion you are using, but indeed, there’s no built-in way to map regular document positions to text offsets, and you’d have to write a routine for that yourself.

1 Like

Sorry, i forgot that .getText() is the part of TipTap editor, which is built on top of the ProseMirror.

Anyway, thanks for the fast reply!