If someonehas got the answer...
(please, answer on StackOverflow, and if you see this on Twitter, keep in mind that's a bot which transfers my messages from Mastodon now, so I don't look Twitter answers)
https://stackoverflow.com/questions/65640736/get-start-and-end-postion-of-a-text-selection-with-sourrounded-elements