Hi!
I’m working on an autocomplete feature in a ProseMirror-based editor where Markdown is used for text formatting. I’ve encountered an issue related to cursor position shifting when inserting Markdown tokens.
The problem:
When the user enters Markdown symbols (e.g., *
for creating lists or formatting text), I need to accurately track the cursor position and the number of Markdown characters before it. The problem arises when these characters affect the correct cursor positioning or when autocomplete behaves unexpectedly.
What I’ve already implemented:
- I have a function that calculates the current cursor position and removes Markdown tags from the text for clean autocomplete processing.
- I’m using ProseMirror, and the text is passed via the
value
prop. - To calculate the cursor position, I’m using
this.view
.
What I need:
How can I properly calculate the Markdown token offsets and adjust the cursor position so that the autocomplete works correctly when typing? I’d appreciate any advice or code examples.