I’m implementing a search system using library prosemirror-search
, but I’ve come across a requirement where I want to get the index of the currently highlighted match, can you provide a solution to implement it, thanks!
like this:
I’m implementing a search system using library prosemirror-search
, but I’ve come across a requirement where I want to get the index of the currently highlighted match, can you provide a solution to implement it, thanks!
like this:
@codemirror/search doesn’t count the total number of matches or number the current match, so it won’t really help with this.
I just keep track of the index myself.
To get the max matches, repeatedly call find next (). You can also get the current index by calculating the count from the beginning to the nearest index from the cursor.
Thank you, this is a nice idea.
OK, also thank you. And I found a solution and code from this issue: functions to get information about the current matching texts of a SearchQuery · Issue #3 · ProseMirror/prosemirror-search · GitHub
It’s works!